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

Pydantic dataclass subclass names flagged as warning by inspection #267

Closed
cslominski opened this issue Apr 8, 2021 · 5 comments
Closed
Labels

Comments

@cslominski
Copy link

In PyCharm 2021.1, which just became the version in Ubuntu, and Pydantic Plugin 0.2.1, the names of pydantic Dataclass subclasses seem to be lost in the code reference, leading to these kind of inspection warnings:

@pydantic.dataclasses.dataclass
class MyDataclass:
pass

def my_fn() -> MyDataclass:
return MyDataclass()

"Expected type 'MyDataclass', got 'Dataclass' instead"

I don't see these in Jupyter Notebooks, but I do see them in .py files.

Additionally, if I Ctrl+B (Go To Declaration or Usages) on the MyDataclass instantiation, it takes me to pydantic/dataclasses.py and not my definition. This behavior I see in both Notebooks and .py files.

Thanks!
Charlie

@koxudaxi
Copy link
Owner

@cslominski
Thank you for creating this issue.
I can reproduce this problem with pydantic 1.7.
The problem doesn't happen with pydantic 1.6.
pydantic had changed the implementation for type-checking.

OK, I will fix it.

@cslominski
Copy link
Author

Thanks @koxudaxi

@koxudaxi
Copy link
Owner

Also, The problem doesn't happen in PyCharm 2020.3 🤔

This was referenced Apr 12, 2021
@koxudaxi
Copy link
Owner

@cslominski
I have released a fixed version as 0.3.0
Would you please check it?

@koxudaxi
Copy link
Owner

Details of the problem

  1. PyCharm 2021.1 detects types of decorators. PyCharm 2020.3 doesn't work the feature.
  2. @pydantic.dataclasses.dataclass returns Dataclass as stub type. the type is in since pydantic version 1.7

The problem happened to combine 1. and 2.
I fixed the problem by ignoring Dataclass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants