MCPcopy Index your code
hub / github.com/python/cpython / _from_module

Method _from_module

Lib/doctest.py:971–998  ·  view source on GitHub ↗

Return true if the given object is defined in the given module.

(self, module, object)

Source from the content-addressed store, hash-verified

969 return tests
970
971 def _from_module(self, module, object):
972 """
973 Return true if the given object is defined in the given
974 module.
975 """
976 if module is None:
977 return True
978 elif inspect.getmodule(object) is not None:
979 return module is inspect.getmodule(object)
980 elif inspect.isfunction(object):
981 return module.__dict__ is object.__globals__
982 elif (inspect.ismethoddescriptor(object) or
983 inspect.ismethodwrapper(object)):
984 if hasattr(object, '__objclass__'):
985 obj_mod = object.__objclass__.__module__
986 elif hasattr(object, '__module__'):
987 obj_mod = object.__module__
988 else:
989 return True # [XX] no easy way to tell otherwise
990 return module.__name__ == obj_mod
991 elif inspect.isclass(object):
992 return module.__name__ == object.__module__
993 elif hasattr(object, '__module__'):
994 return module.__name__ == object.__module__
995 elif isinstance(object, property):
996 return True # [XX] no way not be sure.
997 else:
998 raise ValueError("object must be a class or function")
999
1000 def _is_routine(self, obj):
1001 """

Callers 1

_findMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected