Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors with pydantic 2 when using Field(...) #24

Closed
noamk-hl opened this issue Jul 23, 2023 · 0 comments
Closed

Errors with pydantic 2 when using Field(...) #24

noamk-hl opened this issue Jul 23, 2023 · 0 comments

Comments

@noamk-hl
Copy link

Problem description

After migrating my code to pydantic 2, and having all the tests passing, I'm still getting various pylint errors, where pylint seems to detect the wrong type for fields having explicit Field(...) customization. I think the solution might be to do something like this, and I might have some time to do it but I'm not very familiar with pylint/astroid internals and I wanted someone else to take a look before I work on a PR.

Steps to reproduce the problem

This fails:

from pydantic import BaseModel, Field


class MyModel(BaseModel):
    data: dict[float, float] = Field(default_factory=dict)

    def get_data(self, key: float) -> float:
        return self.data[key]

with

E1136: Value 'self.data' is unsubscriptable (unsubscriptable-object)

Specifications like the version of the project, operating system, or hardware

  • pylint version: 2.17.4
  • pydatic version: 2.0.3
  • python version: 3.10.12
  • pylint-pydantic version: 0.2.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant