Skip to content

Missing Member for Pydantic Model #8759

Open
@alvinmaottd

Description

@alvinmaottd

Bug description

hey team, I'm running into:
E1101: Instance of 'Response' has no 'versionInfo' member (no-member)
Provided the following code:

☁  test_py  cat main.py 
from response import Response
from run import f

r = f()
r.versionInfo = r.versionInfo | {"hi":"bye"}
print(r)%                                                                                                                                                                                     ☁  test_py  cat response.py 
from pydantic import BaseModel


class Response(BaseModel):
    versionInfo: dict[str, str]
    fm: dict[int, float]
☁  test_py  cat run.py 
from response import Response

def f() -> Response:
  return Response(verionInfo={}, fm={})%

Running pylint on main.py I get the following:
main.py:5:16: E1101: Instance of 'Response' has no 'versionInfo' member (no-member)

However, versionInfo is defined in the Response class.

I've got a theory for what's wrong and a work around. Specifically, I think it has something to do with how the BaseModel in pydantic isn't defining the fields using self / something more python native. When I replace the BaseModel with a normal class and define the fields with self linting passes.

Curious what the team thought should be done here. It's not strictly a bug given it's related to a separate dependency in pydantic.

Configuration

pylint 2.17.0
astroid 2.15.0
Python 3.9.6 (default, May  7 2023, 23:32:44) 
[Clang 14.0.3 (clang-1403.0.22.14.1)]

Command used

☁  test_py  pylint main.py

Pylint output

************* Module main
main.py:6:0: C0304: Final newline missing (missing-final-newline)
main.py:1:0: C0114: Missing module docstring (missing-module-docstring)
main.py:5:16: E1101: Instance of 'Response' has no 'versionInfo' member (no-member)
main.py:1:0: W0611: Unused Response imported from response (unused-import)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

Expected behavior

************* Module main
main.py:6:0: C0304: Final newline missing (missing-final-newline)
main.py:1:0: C0114: Missing module docstring (missing-module-docstring)
main.py:1:0: W0611: Unused Response imported from response (unused-import)

^ no more:
main.py:5:16: E1101: Instance of 'Response' has no 'versionInfo' member (no-member)
or the option to do away with it.

Pylint version

pylint 2.17.0
astroid 2.15.0
Python 3.9.6 (default, May  7 2023, 23:32:44) 
[Clang 14.0.3 (clang-1403.0.22.14.1)]

OS / Environment

ProductName: macOS
ProductVersion: 13.4
BuildVersion: 22F66

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Lib specific 💅This affect the code from a particular libraryNeeds decision 🔒Needs a decision before implemention or rejection

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions