MCPcopy Index your code
hub / github.com/numpy/numpy / FindFuncs

Class FindFuncs

numpy/tests/test_warnings.py:26–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25
26class FindFuncs(ast.NodeVisitor):
27 def __init__(self, filename):
28 super().__init__()
29 self.__filename = filename
30
31 def visit_Call(self, node):
32 p = ParseCall()
33 p.visit(node.func)
34 ast.NodeVisitor.generic_visit(self, node)
35
36 if p.ls[-1] == 'simplefilter' or p.ls[-1] == 'filterwarnings':
37 if node.args and getattr(node.args[0], "value", None) == "ignore":
38 if not self.__filename.name.startswith("test_"):
39 raise AssertionError(
40 "ignore filters should only be used in tests; "
41 f"found in {self.__filename} on line {node.lineno}")
42
43 if p.ls[-1] == 'warn' and (
44 len(p.ls) == 1 or p.ls[-2] == 'warnings'):
45
46 if "testing/tests/test_warnings.py" == self.__filename:
47 # This file
48 return
49
50 # See if stacklevel or skip_file_prefixes exists:
51 if len(node.args) == 3:
52 return
53 args = {kw.arg for kw in node.keywords}
54 if "stacklevel" in args:
55 return
56 if "skip_file_prefixes" in args:
57 return
58 raise AssertionError(
59 "warnings should have an appropriate stacklevel or skip_file_prefixes; "
60 f"found in {self.__filename} on line {node.lineno}")
61
62
63@pytest.mark.slow

Callers 1

test_warning_callsFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_warning_callsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…