astroid icon indicating copy to clipboard operation
astroid copied to clipboard

test_pydantic_field failes

Open FantasqueX opened this issue 4 months ago • 2 comments

Steps to reproduce

  1. git clone https://github.com/pylint-dev/astroid.git
  2. python3.12 -m virtualenv .venv
  3. source ./.venv/bin/activate.fish
  4. pip install -e .
  5. pip install pydantic
  6. pytest

Current behavior

_________________________________________________ test_pydantic_field __________________________________________________

    def test_pydantic_field() -> None:
        """Test that pydantic.Field attributes are currently Uninferable.

        (Eventually, we can extend the brain to support pydantic.Field)
        """
        klass, instance = astroid.extract_node(
            """
        from pydantic import Field
        from pydantic.dataclasses import dataclass

        @dataclass
        class A:
            name: str = Field("hi")

        A.name  #@
        A().name #@
        """
        )

        inferred = klass.inferred()
        assert len(inferred) == 1
>       assert inferred[0] is Uninferable
E       assert <Instance of pydantic.fields.FieldInfo at 0x140034371510752> is Uninferable

tests/brain/test_dataclasses.py:461: AssertionError

Expected behavior

Test passes.

python -c "from astroid import __pkginfo__; print(__pkginfo__.version)" output

3.2.0-dev0

This problem was found when I try to package astroid 2.15.6 for ArchLinux. And I noticed that Gentoo deselected this test since 2.15.6 https://github.com/gentoo/gentoo/commit/70a46fcd283b608171fd5529619915e119b69405

FantasqueX avatar Feb 28 '24 04:02 FantasqueX

Thank you for opening the issue. It could be that it's now easier to infer the value of pydantic fields when pydantic is actually installed without any help from the brain. Most libs' brains are tested without the lib being instaled in our continuous integration which could explain the issue. (Need investigation this is all intuition and I'm on mobile).

Pierre-Sassoulas avatar Feb 29 '24 07:02 Pierre-Sassoulas

It seems that pydantic is missing from the requirements_full.txt. Note also a similar test where attrs is required and the test will be skipped if attrs is not installed. attrs is in the requirements_full.txt.

mbyrnepr2 avatar Apr 05 '24 12:04 mbyrnepr2