9393
9494# these names are known to fail doctesting and we like to keep it that way
9595# e.g. sometimes pseudocode is acceptable etc
96- DOCTEST_SKIPLIST = set ([
96+ #
97+ # Optionally, a subset of methods can be skipped by setting dict-values
98+ # to a container of method-names
99+ DOCTEST_SKIPDICT = {
97100 # cases where NumPy docstrings import things from SciPy:
98- 'numpy.lib.vectorize' ,
99- 'numpy.random.standard_gamma' ,
100- 'numpy.random.gamma' ,
101- 'numpy.random.vonmises' ,
102- 'numpy.random.power' ,
103- 'numpy.random.zipf' ,
101+ 'numpy.lib.vectorize' : None ,
102+ 'numpy.random.standard_gamma' : None ,
103+ 'numpy.random.gamma' : None ,
104+ 'numpy.random.vonmises' : None ,
105+ 'numpy.random.power' : None ,
106+ 'numpy.random.zipf' : None ,
104107 # remote / local file IO with DataSource is problematic in doctest:
105- 'numpy.lib.DataSource' ,
106- 'numpy.lib.Repository' ,
107- ])
108+ 'numpy.lib.DataSource' : None ,
109+ 'numpy.lib.Repository' : None ,
110+ }
111+ if sys .version_info < (3 , 9 ):
112+ DOCTEST_SKIPDICT .update ({
113+ "numpy.core.ndarray" : {"__class_getitem__" },
114+ "numpy.core.dtype" : {"__class_getitem__" },
115+ "numpy.core.number" : {"__class_getitem__" },
116+ })
108117
109118# Skip non-numpy RST files, historical release notes
110119# Any single-directory exact match will skip the directory and all subdirs.
@@ -870,8 +879,12 @@ def check_doctests(module, verbose, ns=None,
870879 for name in get_all_dict (module )[0 ]:
871880 full_name = module .__name__ + '.' + name
872881
873- if full_name in DOCTEST_SKIPLIST :
874- continue
882+ if full_name in DOCTEST_SKIPDICT :
883+ skip_methods = DOCTEST_SKIPDICT [full_name ]
884+ if skip_methods is None :
885+ continue
886+ else :
887+ skip_methods = None
875888
876889 try :
877890 obj = getattr (module , name )
@@ -892,6 +905,10 @@ def check_doctests(module, verbose, ns=None,
892905 traceback .format_exc ()))
893906 continue
894907
908+ if skip_methods is not None :
909+ tests = [i for i in tests if
910+ i .name .partition ("." )[2 ] not in skip_methods ]
911+
895912 success , output = _run_doctests (tests , full_name , verbose ,
896913 doctest_warnings )
897914
@@ -972,7 +989,7 @@ def check_doctests_testfile(fname, verbose, ns=None,
972989 results = []
973990
974991 _ , short_name = os .path .split (fname )
975- if short_name in DOCTEST_SKIPLIST :
992+ if short_name in DOCTEST_SKIPDICT :
976993 return results
977994
978995 full_name = fname
0 commit comments