| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
| IGNORED_DUNDERS = frozenset({ | ||
| # Very special attributes | ||
| "__weakref__", | ||
| "__slots__", | ||
| "__dict__", | ||
| "__text_signature__", | ||
| "__match_args__", | ||
| # Pickle methods | ||
| "__setstate__", | ||
| "__getstate__", | ||
| "__getnewargs__", | ||
| "__getinitargs__", | ||
| "__reduce_ex__", | ||
| "__reduce__", | ||
| # typing implementation details | ||
| "__parameters__", | ||
| "__origin__", | ||
| "__args__", | ||
| "__orig_bases__", | ||
| "__mro_entries__", | ||
| "__forward_is_class__", | ||
| "__forward_module__", | ||
| "__final__", | ||
| # isinstance/issubclass hooks that type-checkers don't usually care about | ||
| "__instancecheck__", | ||
| "__subclasshook__", | ||
| "__subclasscheck__", | ||
| # Dataclasses implementation details | ||
| "__dataclass_fields__", | ||
| "__dataclass_params__", | ||
| # ctypes weirdness | ||
| "__ctype_be__", | ||
| "__ctype_le__", | ||
| "__ctypes_from_outparam__", | ||
| # Two float methods only used internally for CPython test suite, not for public use | ||
| "__set_format__", | ||
| "__getformat__", | ||
| # These two are basically useless for type checkers | ||
| "__hash__", | ||
| "__getattr__", | ||
| # For some reason, mypy doesn't infer classes with metaclass=ABCMeta inherit this attribute | ||
| "__abstractmethods__", | ||
| "__doc__", # Can only ever be str | None, who cares? | ||
| "__del__", # Only ever called when an object is being deleted, who cares? | ||
| "__new_member__", # If an enum defines __new__, the method is renamed as __new_member__ | ||
| }) |
There was a problem hiding this comment.
This is a fairly arbitrary ignorelist, based on the hits that this patch initially came up with, combined with my judgement as to which were worth fixing and which weren't. I'm happy to add or remove items!
Sorry, something went wrong.
There was a problem hiding this comment.
This is great, thanks for doing this!
Sorry, something went wrong.
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Sorry, something went wrong.
|
Thanks! :D |
Sorry, something went wrong.
Basically a follow up to #12203 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.
This isn't actually a reversion. This logic was asymmetrical for reasons lost to time. Although I suspect it was this way because it introduced only a few errors on typeshed. What changed was that as a result of python#12203 we actually started checking a lot more dunder methods. Previously, we only checked dunders if either: a) it was a special dunder, like __init__ or __call, or b) the dunder was defined on the actual stub class itself In particular, we started checking every dunder redefined at runtime that the stub just inherited from object. A possible intermediate option would be to not check positional-only arguments in the case where a stub inherits the definition. I'll experiment with that once typeshed CI is green.
This isn't actually a reversion. This logic was asymmetrical for reasons lost to time. Although I suspect it was this way because the delta only a few errors on typeshed. What changed was that as a result of #12203 we actually started checking a lot more dunder methods. Previously, we only checked dunders if either: a) it was a special dunder, like `__init__` or `__call__`, or b) the dunder was defined on the actual stub class itself In particular, we started checking every dunder redefined at runtime that the stub just inherited from object. A possible intermediate option would be to not check positional-only arguments in the case where a stub inherits the definition. I'll experiment with that once typeshed CI is green. Co-authored-by: hauntsaninja <>
| Back | FazBrowse Home | New Git URL |
Description
This PR alters stubtest so that it raises an error if a dunder method is missing from a stub. Currently, stubtest does raise an error for a few missing dunders (__call__, __class_getitem__, etc.). However, for the vast majority of them, it does not raise an error.
I have been using this patch to provide a number of fixes to typeshed over the past week or so:
DetailsWith these typeshed fixes merged, here are the new errors stubtest reports from checking typeshed, with this patch applied:
DetailsNotes on the new errors reported
Test Plan
I've altered the existing tests so they continue to pass, and added two new test cases.
cc. @hauntsaninja: here is the promised follow-up PR!