Find the module an object belong to.
(obj, name)
| 333 | return obj, parent |
| 334 | |
| 335 | def 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 | |
| 354 | def encode_long(x): |
| 355 | r"""Encode a long to a two's complement little-endian binary string. |
no test coverage detected