astroid
astroid copied to clipboard
test_pydantic_field failes
Steps to reproduce
-
git clone https://github.com/pylint-dev/astroid.git
-
python3.12 -m virtualenv .venv
-
source ./.venv/bin/activate.fish
-
pip install -e .
-
pip install pydantic
-
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
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).
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.