Skip to content
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

Merged
merged 1 commit into from
Nov 22, 2021
Merged

Factor out field_makers alongside dataclass_makers #11584

merged 1 commit into from
Nov 22, 2021

Conversation

NeilGirdhar
Copy link
Contributor

@NeilGirdhar NeilGirdhar commented Nov 21, 2021

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.

@@ -20,10 +20,15 @@
from mypy.server.trigger import make_wildcard_trigger

# The set of decorators that generate dataclasses.
dataclass_makers: Final = {
dataclass_makers = {
Copy link
Member

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?

Copy link
Contributor Author

@NeilGirdhar NeilGirdhar Nov 21, 2021

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Copy link
Member

@JelleZijlstra JelleZijlstra left a 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 :)

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

Successfully merging this pull request may close these issues.

3 participants