MCPcopy Index your code
hub / github.com/RustPython/RustPython / find

Method find

Lib/doctest.py:875–975  ·  view source on GitHub ↗

Return a list of the DocTests that are defined by the given object's docstring, or by any of its contained objects' docstrings. The optional parameter `module` is the module that contains the given object. If the module is not specified or is None, then

(self, obj, name=None, module=None, globs=None, extraglobs=None)

Source from the content-addressed store, hash-verified

873 self._exclude_empty = exclude_empty
874
875 def find(self, obj, name=None, module=None, globs=None, extraglobs=None):
876 """
877 Return a list of the DocTests that are defined by the given
878 object's docstring, or by any of its contained objects'
879 docstrings.
880
881 The optional parameter `module` is the module that contains
882 the given object. If the module is not specified or is None, then
883 the test finder will attempt to automatically determine the
884 correct module. The object's module is used:
885
886 - As a default namespace, if `globs` is not specified.
887 - To prevent the DocTestFinder from extracting DocTests
888 from objects that are imported from other modules.
889 - To find the name of the file containing the object.
890 - To help find the line number of the object within its
891 file.
892
893 Contained objects whose module does not match `module` are ignored.
894
895 If `module` is False, no attempt to find the module will be made.
896 This is obscure, of use mostly in tests: if `module` is False, or
897 is None but cannot be found automatically, then all objects are
898 considered to belong to the (non-existent) module, so all contained
899 objects will (recursively) be searched for doctests.
900
901 The globals for each DocTest is formed by combining `globs`
902 and `extraglobs` (bindings in `extraglobs` override bindings
903 in `globs`). A new copy of the globals dictionary is created
904 for each DocTest. If `globs` is not specified, then it
905 defaults to the module's `__dict__`, if specified, or {}
906 otherwise. If `extraglobs` is not specified, then it defaults
907 to {}.
908
909 """
910 # If name was not specified, then extract it from the object.
911 if name is None:
912 name = getattr(obj, '__name__', None)
913 if name is None:
914 raise ValueError("DocTestFinder.find: name must be given "
915 "when obj.__name__ doesn't exist: %r" %
916 (type(obj),))
917
918 # Find the module that contains the given object (if obj is
919 # a module, then module=obj.). Note: this may fail, in which
920 # case module will be None.
921 if module is False:
922 module = None
923 elif module is None:
924 module = inspect.getmodule(obj)
925
926 # Read the module's source code. This is used by
927 # DocTestFinder._find_lineno to find the line number for a
928 # given object's docstring.
929 try:
930 file = inspect.getsourcefile(obj)
931 except TypeError:
932 source_lines = None

Callers 15

testmodFunction · 0.95
run_docstring_examplesFunction · 0.95
DocTestSuiteFunction · 0.95
findMethod · 0.95
test_issue35753Method · 0.95
readlineMethod · 0.45
_findallFunction · 0.45
unicodeescape_stringFunction · 0.45
_translateFunction · 0.45
_parse_isoformat_timeFunction · 0.45
_expand_langFunction · 0.45

Calls 5

_findMethod · 0.95
getattrFunction · 0.85
copyMethod · 0.45
updateMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected