10000 ENH: add runtests option to find untyped module attributes by person142 · Pull Request #53 · numpy/numpy-stubs · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 10, 2020. It is now read-only.

ENH: add runtests option to find untyped module attributes #53

Merged
merged 3 commits into from
Apr 22, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
Prev Previous commit
MAINT: run black on runtests.py
  • Loading branch information
person142 committed Apr 22, 2020
commit 415b59311e7f9fb2191930e844a4687be724a8b6
65 changes: 32 additions & 33 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@
# Technically "public" functions (they don't start with an underscore)
# that we don't want to include.
BLACKLIST = {
'numpy': {
"numpy": {
# Stdlib modules in the namespace by accident
'absolute_import',
'warnings',
"absolute_import",
"warnings",
# Accidentally public
'add_docstring',
'add_newdoc',
'add_newdoc_ufunc',
"add_docstring",
"add_newdoc",
"add_newdoc_ufunc",
# Builtins
'bool',
'complex',
'float',
'int',
'long',
'object',
'str',
'unicode',
"bool",
"complex",
"float",
"int",
"long",
"object",
"str",
"unicode",
# Should use numpy_financial instead
'fv',
'ipmt',
'irr',
'mirr',
'nper',
'npv',
'pmt',
'ppmt',
'pv',
'rate',
},
"fv",
"ipmt",
"irr",
"mirr",
"nper",
"npv",
"pmt",
"ppmt",
"pv",
"rate",
}
}


Expand All @@ -60,7 +60,7 @@ def __init__(self):
self.attributes = set()

def visit_FunctionDef(self, node):
if node.name == '__getattr__':
if node.name == "__getattr__":
# Not really a module member.
return
self.attributes.add(node.name)
Expand All @@ -69,7 +69,7 @@ def visit_FunctionDef(self, node):
return

def visit_ClassDef(self, node):
if not node.name.startswith('_'):
if not node.name.startswith("_"):
self.attributes.add(node.name)
return

Expand All @@ -80,14 +80,13 @@ def visit_AnnAssign(self, node):
def find_missing(module_name):
module_path = os.path.join(
STUBS_ROOT,
module_name.replace('numpy', 'numpy-stubs').replace('.', os.sep),
'__init__.pyi',
module_name.replace("numpy", "numpy-stubs").replace(".", os.sep),
"__init__.pyi",
)

module = importlib.import_module(module_name)
module_attributes = {
attribute for attribute in dir(module)
if not attribute.startswith('_')
attribute for attribute in dir(module) if not attribute.startswith("_")
}

if os.path.isfile(module_path):
Expand All @@ -103,7 +102,7 @@ def find_missing(module_name):
blacklist = BLACKLIST.get(module_name, set())

missing = module_attributes - stubs_attributes - blacklist
print('\n'.join(sorted(missing)))
print("\n".join(sorted(missing)))


def run_pytest(argv):
Expand All @@ -117,7 +116,7 @@ def run_pytest(argv):

def main():
parser = argparse.ArgumentParser()
parser.add_argument('--find-missing')
parser.add_argument("--find-missing")
args, remaining_argv = parser.parse_known_args()

if args.find_missing is not None:
Expand Down
0