Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
inspect function shim
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
  • Loading branch information
arihant2math committed Feb 17, 2025
commit 9166b80ae7f7273831764c02511ac6f707304662
20 changes: 20 additions & 0 deletions Lib/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,26 @@ def _check_class(klass, attr):
pass
return _sentinel



@functools.lru_cache()
def _shadowed_dict_from_weakref_mro_tuple(*weakref_mro):
for weakref_entry in weakref_mro:
# Normally we'd have to check whether the result of weakref_entry()
# is None here, in case the object the weakref is pointing to has died.
# In this specific case, however, we know that the only caller of this
# function is `_shadowed_dict()`, and that therefore this weakref is
# guaranteed to point to an object that is still alive.
entry = weakref_entry()
dunder_dict = _get_dunder_dict_of_class(entry)
if '__dict__' in dunder_dict:
class_dict = dunder_dict['__dict__']
if not (type(class_dict) is types.GetSetDescriptorType and
class_dict.__name__ == "__dict__" and
class_dict.__objclass__ is entry):
return class_dict
return _sentinel

def _is_type(obj):
try:
_static_getmro(obj)
Expand Down