-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
stubtest: error if module level dunder is missing, housekeeping #12217
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
Conversation
New errors in typeshed from this: ``` _decimal.__libmpdec_version__ is not present in stub _heapq.__about__ is not present in stub builtins.__build_class__ is not present in stub cgitb.__UNDEF__ is not present in stub decimal.__libmpdec_version__ is not present in stub sys.__unraisablehook__ is not present in stub ``` Some general housekeeping, moving things around, renaming things, adding some comments.
cc @AlexWaygood |
"__new_member__", # If an enum defines __new__, the method is renamed as __new_member__ | ||
"__dataclass_fields__", # Generated by dataclasses | ||
"__dataclass_params__", # Generated by dataclasses | ||
"__doc__", # mypy's semanal for namedtuples assumes this is str, not Optional[str] |
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 one should be a pretty easy fix
# TODO: remove the following from this list | ||
"__author__", | ||
"__version__", | ||
"__copyright__", |
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.
"__copyright__", | |
"__copyright__", | |
"__about__", |
Another one I noticed in my experiments recently!
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 you consider heap.__about__
a true positive?
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.
I guess we could just put __about__: str
in the stub. Doesn't do any harm.
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.
It's quite educational :D
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.
My reasoning here is that it's only clearly a true negative if the Python runtime is what's creating the attribute. Everything else you might conceivably want to have stubbed. I'm especially eager to remove __version__
from this list, which is widely used in third party stubs.
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.
Sure, that makes sense!
@@ -204,7 +209,7 @@ def verify_mypyfile( | |||
to_check = set( | |||
m | |||
for m, o in stub.names.items() | |||
if not o.module_hidden and (not m.startswith("_") or hasattr(runtime, m)) | |||
if not o.module_hidden and (not is_probably_private(m) or hasattr(runtime, m)) |
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.
I was planning something very similar, which was why I factored it out into a helper function even though it was only used once in my patch 😆
This comment has been minimized.
This comment has been minimized.
This causes us to error if |
😡 |
I think it should be fine? I can't think of any scenarios off the top of my head where that would be a problem 🙂 |
I was thinking something like: you're adding stubs for a third party module and want to use |
Why don't we just add |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
That would be a regression from the status quo, since we wouldn't check |
Basically a follow up to #12203
New errors in typeshed from this:
Some general housekeeping, moving things around, renaming things, adding
some comments.