-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
Fix dataclass inference for marshmallow_dataclass #1298
Fix dataclass inference for marshmallow_dataclass #1298
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the MR. I discovered this package and it fix a problem I had with marshmallow's design 😄
Regarding the change itself, I'm thinking there might be a problem with our design if we need to add the name of all dataclasses modules to this constant. I don't have a better solution as it's astroid and not pylint we can't add an option to let user add their own data-classes.
I took a quick look at how Even if we did find the correct function definition it would be difficult to fix this. We currently infer this as the return value from Making sure that all of these return values are dataclasses would require us to go several levels deeper and might be unfeasible. I think for now this might be the best thing we can do.. |
I think the way you're probably meant to deal with it would be trough a custom pylint / astroid plugin. |
Sounds good, but do we have astroid plugins ? If we go this route, each astroid brains could be an astroid plugins ? Seems to me a good idea as brains need to handle multiple versions of a package (?) and are rather naive in their current implementation. Having external astroid brains would permit to make them a lot more complicated than what they currently are. Then a pylint option could permits to add brain packages to your project. Thoughts @hippo91 ? |
Aren't those the Transform plugins? It looks like those should work with
Most brain modules are actually for builtin functions and classes. Those should definitely stay within astroid. For the external once (like numpy) there could be an argument to move them to new projects. The issue then just becomes who will maintain them? For simple brains it's certainly much easier to add them to astroid directly. In the end, I would think of it as batteries included. If it isn't too difficult or a very popular library, add it to astroid. For more complex stuff that might also require more maintenance than we can provide, a separate package is probably better. |
@Pierre-Sassoulas i definitely agree with @cdce8p remarks! |
Glad to see you're back and thanks for taking the time to check the problem ;)
I wonder the criteria we could use. Maybe popularity of the package and the complexity of maintaining multiple versions together. Libraries like numpy and pandas are complex but also used a lot so keeping them in astroid makes some sense. The same question arise when we're asking ourselves about what dependency should be installed during tests (should we install numpy ? If we had an |
The whole discussion should probably be moved to two separate issues:
Some last comments, the package name should probably be something like -- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an external library but it's rather popular (350 star right now, but it's linked to marshmallow which is a lot more popular), and it's simple to maintain so following the rules we talked about, it can be included so astroid has "battery included".
Follow-up discussion in #1312
Steps
Description
This allows astroid/pylint to understand dataclasses as provided by marshmallow-dataclass, which are basically regular stdlib dataclasses with a few additional private attributes to generate marshmallow schemas from said dataclasses declaration.
Note that despite the fact that this affects inference for both
dataclass
andfield
, pylint still correctly detects thatmarshmallow-dataclass
does not provide afield
function.Type of Changes
(I'm putting this down as a bugfix because this was "broken" by the fact that recent astroid/pylint versions now correctly infers types from dataclasses, but I guess this could be considered a new feature)