parameters: (obj, name)
return_statement: return None
docstring: Find the module an object belongs to.
  
      This function differs from ``pickle.whichmodule`` in two ways:
      - it does not mangle the cases where obj's module is __main__ and obj was
        not found in any module.
      - Errors arising during module introspection are ignored, as those errors
        are considered unwanted side effects.
docstring_summary: Find the module an object belongs to.
docstring_tokens: Find the module an object belongs to .
function: def _whichmodule(obj, name):
      """Find the module an object belongs to.
  
      This function differs from ``pickle.whichmodule`` in two ways:
      - it does not mangle the cases where obj's module is __main__ and obj was
        not found in any module.
      - Errors arising during module introspection are ignored, as those errors
        are considered unwanted side effects.
      """
      if sys.version_info[:2] < (3, 7) and isinstance(obj, typing.TypeVar):  # pragma: no branch  # noqa
          # Workaround bug in old Python versions: prior to Python 3.7,
          # T.__module__ would always be set to "typing" even when the TypeVar T
          # would be defined in a different module.
          #
          # For such older Python versions, we ignore the __module__ attribute of
          # TypeVar instances and instead exhaustively lookup those instances in
          # all currently imported modules.
          module_name = None
      else:
          module_name = getattr(obj, '__module__', None)
  
      if module_name is not None:
          return module_name
      # Protect the iteration by using a copy of sys.modules against dynamic
      # modules that trigger imports of other modules upon calls to getattr or
      # other threads importing at the same time.
      for module_name, module in sys.modules.copy().items():
          # Some modules such as coverage can inject non-module objects inside
          # sys.modules
          if (
                  module_name == '__main__' or
                  module is None or
                  not isinstance(module, types.ModuleType)
          ):
              continue
          try:
              if _getattribute(module, name)[0] is obj:
                  return module_name
          except Exception:
              pass
      return None
function_tokens: def _whichmodule ( obj , name ) : if sys . version_info [ : 2 ] < ( 3 , 7 ) and isinstance ( obj , typing . TypeVar ) : # pragma: no branch  # noqa # Workaround bug in old Python versions: prior to Python 3.7, # T.__module__ would always be set to "typing" even when the TypeVar T # would be defined in a different module. # # For such older Python versions, we ignore the __module__ attribute of # TypeVar instances and instead exhaustively lookup those instances in # all currently imported modules. module_name = None else : module_name = getattr ( obj , '__module__' , None ) if module_name is not None : return module_name # Protect the iteration by using a copy of sys.modules against dynamic # modules that trigger imports of other modules upon calls to getattr or # other threads importing at the same time. for module_name , module in sys . modules . copy ( ) . items ( ) : # Some modules such as coverage can inject non-module objects inside # sys.modules if ( module_name == '__main__' or module is None or not isinstance ( module , types . ModuleType ) ) : continue try : if _getattribute ( module , name ) [ 0 ] is obj : return module_name except Exception : pass return None