MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / whichmodule

Function whichmodule

tools/python-3.11.9-amd64/Lib/pickle.py:335–352  ·  view source on GitHub ↗

Find the module an object belong to.

(obj, name)

Source from the content-addressed store, hash-verified

333 return obj, parent
334
335def whichmodule(obj, name):
336 """Find the module an object belong to."""
337 module_name = getattr(obj, '__module__', None)
338 if module_name is not None:
339 return module_name
340 # Protect the iteration by using a list copy of sys.modules against dynamic
341 # modules that trigger imports of other modules upon calls to getattr.
342 for module_name, module in sys.modules.copy().items():
343 if (module_name == '__main__'
344 or module_name == '__mp_main__' # bpo-42406
345 or module is None):
346 continue
347 try:
348 if _getattribute(module, name)[0] is obj:
349 return module_name
350 except AttributeError:
351 pass
352 return '__main__'
353
354def encode_long(x):
355 r"""Encode a long to a two's complement little-endian binary string.

Callers 1

save_globalMethod · 0.85

Calls 3

_getattributeFunction · 0.85
itemsMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected