Custom dataclass support
See original GitHub issueHey,
We are using custom pydantic dataclass that wrapped original pydantic dataclass. It contains some helper serializing function etc. as extra. And generally behaving as pydantic dataclass (same arguments, same return types).
And we import directly our dataclass decorator like below;
from my_package import dataclass
@dataclass
class MyModel:
name : str
# it's warning as 'Unexpected Arguments'
my_model = MyModel(name='Tom')
As workaround we can import as below and get rid of warning.
if TYPE_CHECKING:
from pydantic.dataclasses import dataclass
else:
from my_package import dataclass
But it should be same file with file that defined of model class. I want to add one time this conditional statement and centralized location for example __init__.py
file of custom packege like below.
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from pydantic.dataclasses import dataclass
else:
from .dataclass import dataclass
__all__ = [
"dataclass",
]
I guess plugin examine only import on file which model defined. I think not important structure of new dataclass because also if we import original dataclass in different module and then import this module and use dataclass like chain, again plugin not recognize pydantic dataclass. It can be supported? Or can you give a new workaround tip for centrailzed importations.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:11 (6 by maintainers)
Top GitHub Comments
There is a bug report in jetbrains about this topic. Link is here. I hope it will pan out. 🙏
Thank you for checking it. I guess PyCharm doesn’t resolve the imported module. It means PyCharm checks only the local module names.