-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
Optimise inspect.getattr_static #103193
Copy link
Copy link
Closed
Labels
3.12only security fixesonly security fixesperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Description
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixesperformancePerformance or resource usagePerformance or resource usagestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement
Fields
Give feedbackNo fields configured for issues without a type.
Feature or enhancement
Following 6d59c9e,
typing._ProtocolMeta.__instancecheck__usesinspect.getattr_staticin a tight loop, where it had previously usedhasattr. This improves semantics in several highly desirable ways, but causes a considerable slowdown for_ProtocolMeta.__instancecheck__, asinspect.getattr_staticis much slower thanhasattr.The performance hit to
_ProtocolMeta.__instancecheck__has already been mostly mitigated through severaltyping-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 ofisinstance()checks against classes subclassingtyping.Protocol. It will also improve the performance of all other tools that useinspect.getattr_staticfor introspection without side effects.Linked PRs
inspect.getattr_static#103195inspect.getattr_static#103318inspect._is_type#103321inspect.getattr_staticin 'What's New in Python 3.12' #103349inspect._shadowed_dictininspect.getattr_static#104267getattr_statictest coverage #104286getattr_statictest coverage (GH-104286) #104290test_inspectandtest_typing#104320