Following 6d59c9e, typing._ProtocolMeta.__instancecheck__
uses inspect.getattr_static
in a tight loop, where it had previously used hasattr
. This improves semantics in several highly desirable ways, but causes a considerable slowdown for _ProtocolMeta.__instancecheck__
, as inspect.getattr_static
is much slower than hasattr
.
The performance hit to _ProtocolMeta.__instancecheck__
has already been mostly mitigated through several typing
-specific optimisations that are tracked in this issue:
However, it would be good to also see if we can improve the performance of inspect.getattr_static
. This will not only improve the performance of isinstance()
checks against classes subclassing typing.Protocol
. It will also improve the performance of all other tools that use inspect.getattr_static
for introspection without side effects.
inspect.getattr_static
#103195inspect.getattr_static
#103318inspect._is_type
#103321inspect.getattr_static
in 'What's New in Python 3.12' #103349inspect._shadowed_dict
in inspect.getattr_static
#104267getattr_static
test coverage #104286getattr_static
test coverage (GH-104286) #104290test_inspect
and test_typing
#104320RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4