Return true if the given object is defined in the given module.
(self, module, object)
| 948 | return tests |
| 949 | |
| 950 | def _from_module(self, module, object): |
| 951 | """ |
| 952 | Return true if the given object is defined in the given |
| 953 | module. |
| 954 | """ |
| 955 | if module is None: |
| 956 | return True |
| 957 | elif inspect.getmodule(object) is not None: |
| 958 | return module is inspect.getmodule(object) |
| 959 | elif inspect.isfunction(object): |
| 960 | return module.__dict__ is object.__globals__ |
| 961 | elif (inspect.ismethoddescriptor(object) or |
| 962 | inspect.ismethodwrapper(object)): |
| 963 | if hasattr(object, '__objclass__'): |
| 964 | obj_mod = object.__objclass__.__module__ |
| 965 | elif hasattr(object, '__module__'): |
| 966 | obj_mod = object.__module__ |
| 967 | else: |
| 968 | return True # [XX] no easy way to tell otherwise |
| 969 | return module.__name__ == obj_mod |
| 970 | elif inspect.isclass(object): |
| 971 | return module.__name__ == object.__module__ |
| 972 | elif hasattr(object, '__module__'): |
| 973 | return module.__name__ == object.__module__ |
| 974 | elif isinstance(object, property): |
| 975 | return True # [XX] no way not be sure. |
| 976 | else: |
| 977 | raise ValueError("object must be a class or function") |
| 978 | |
| 979 | def _is_routine(self, obj): |
| 980 | """ |