-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Factor out field_makers alongside dataclass_makers #11584
Conversation
mypy/plugins/dataclasses.py
Outdated
@@ -20,10 +20,15 @@ | |||
from mypy.server.trigger import make_wildcard_trigger | |||
|
|||
# The set of decorators that generate dataclasses. | |||
dataclass_makers: Final = { | |||
dataclass_makers = { |
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.
Why do you want to remove Final
here?
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.
Just because I am editing it like so: https://github.com/NeilGirdhar/tjax/blob/master/tjax/mypy_plugin.py#L8
(This surprisingly works!)
But I'm happy to revert that change if it makes you uncomfortable.
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.
Oh I see 🙂
There's no need to remove Final
when mutating a variable. Only reassignment is forbidden with Final
.
So, mypy.plugins.dataclasses.dataclass_makers.add('tjax._src.dataclasses.dataclass.dataclass')
is fine. And mypy.plugins.dataclasses.dataclass_makers = []
not.
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.
Ah! Thanks for setting me straight on that. I will re-add Final
now.
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.
Surprised I had to click the "Approve" button on CI for you :)
Description
This is a very minor change that moves the
field_makers
constant up to the global scope.Currently, I have duplicated this entire plugin here https://github.com/NeilGirdhar/tjax/blob/master/tjax/mypy_plugin.py, but it keeps changing.
I would like to simply add my custom dataclass and its field maker to the constant sets, and having them in the global scope (and non-final) makes that easy.