question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom dataclass support

See original GitHub issue

Hey,

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:open
  • Created 2 years ago
  • Reactions:2
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
resulyrt93commented, May 5, 2022

There is a bug report in jetbrains about this topic. Link is here. I hope it will pan out. 🙏

1reaction
koxudaxicommented, Mar 7, 2022

Thank you for checking it. I guess PyCharm doesn’t resolve the imported module. It means PyCharm checks only the local module names.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dataclasses — Data Classes — Python 3.11.1 documentation
If they are used, it might be wise to have alternate class constructors, or perhaps a custom replace() (or similarly named) method which...
Read more >
Data Classes in Python 3.7+ (Guide)
How to customize the ordering of data class objects; How to work with immutable data classes; How inheritance works for data classes. If...
Read more >
using dataclass decorators in Python in custom classes
Python dataclass tutorial shows how to use dataclass decorators in Python in custom classes. The dataclass decorator helps reduce some ...
Read more >
python - How to pass Attributes to Custom Dataclass
The dataclass decorator does essentially two steps while creating a default __init__ instance method for a class:.
Read more >
Advanced Python Data Classes: Custom Tools
Python's dataclasses module, added in 3.7, is a great way to ... to extend data classes to support field validation. dataclass is just...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found