Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 55c701e

Browse filesBrowse files
AlexWaygoodwarsaw
authored andcommitted
pythongh-103193: Micro-optimise helper functions for inspect.getattr_static (python#103195)
1 parent cc9a947 commit 55c701e
Copy full SHA for 55c701e

File tree

2 files changed

+5
-4
lines changed
Filter options

2 files changed

+5
-4
lines changed

‎Lib/inspect.py

Copy file name to clipboardExpand all lines: Lib/inspect.py
+3-4Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1772,9 +1772,9 @@ def trace(context=1):
17721772
# ------------------------------------------------ static version of getattr
17731773

17741774
_sentinel = object()
1775+
_static_getmro = type.__dict__['__mro__'].__get__
1776+
_get_dunder_dict_of_class = type.__dict__["__dict__"].__get__
17751777

1776-
def _static_getmro(klass):
1777-
return type.__dict__['__mro__'].__get__(klass)
17781778

17791779
def _check_instance(obj, attr):
17801780
instance_dict = {}
@@ -1802,10 +1802,9 @@ def _is_type(obj):
18021802
return True
18031803

18041804
def _shadowed_dict(klass):
1805-
dict_attr = type.__dict__["__dict__"]
18061805
for entry in _static_getmro(klass):
18071806
try:
1808-
class_dict = dict_attr.__get__(entry)["__dict__"]
1807+
class_dict = _get_dunder_dict_of_class(entry)["__dict__"]
18091808
except KeyError:
18101809
pass
18111810
else:
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Improve performance of :func:`inspect.getattr_static`. Patch by Alex
2+
Waygood.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.