Return true if the given object is defined in the given module.
(self, module, object)
| 86 | class DocTestFinder(doctest.DocTestFinder): |
| 87 | |
| 88 | def _from_module(self, module, object): |
| 89 | """ |
| 90 | Return true if the given object is defined in the given |
| 91 | module. |
| 92 | """ |
| 93 | if module is None: |
| 94 | return True |
| 95 | elif inspect.isfunction(object): |
| 96 | return module.__dict__ is object.__globals__ |
| 97 | elif inspect.isbuiltin(object): |
| 98 | return module.__name__ == object.__module__ |
| 99 | elif inspect.isclass(object): |
| 100 | return module.__name__ == object.__module__ |
| 101 | elif inspect.ismethod(object): |
| 102 | # This one may be a bug in cython that fails to correctly set the |
| 103 | # __module__ attribute of methods, but since the same error is easy |
| 104 | # to make by extension code writers, having this safety in place |
| 105 | # isn't such a bad idea |
| 106 | return module.__name__ == object.__self__.__class__.__module__ |
| 107 | elif inspect.getmodule(object) is not None: |
| 108 | return module is inspect.getmodule(object) |
| 109 | elif hasattr(object, '__module__'): |
| 110 | return module.__name__ == object.__module__ |
| 111 | elif isinstance(object, property): |
| 112 | return True # [XX] no way not be sure. |
| 113 | elif inspect.ismethoddescriptor(object): |
| 114 | # Unbound PyQt signals reach this point in Python 3.4b3, and we want |
| 115 | # to avoid throwing an error. See also http://bugs.python.org/issue3158 |
| 116 | return False |
| 117 | else: |
| 118 | raise ValueError("object must be a class or function, got %r" % object) |
| 119 | |
| 120 | def _find(self, tests, obj, name, module, source_lines, globs, seen): |
| 121 | """ |