stubtest: error if module level dunder is missing, housekeeping#12217
stubtest: error if module level dunder is missing, housekeeping#12217hauntsaninja merged 4 commits intopython:masterfrom
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.
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.
| "__copyright__", | |
| "__copyright__", | |
| "__about__", |
Another one I noticed in my experiments recently!
There was a problem hiding this comment.
Oh, I see you consider heap.__about__ a true positive?
There was a problem hiding this comment.
I guess we could just put __about__: str in the stub. Doesn't do any harm.
There was a problem hiding this comment.
It's quite educational :D
There was a problem hiding this comment.
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.
| 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.
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.