-
-
Notifications
You must be signed in to change notification settings - Fork 169
TST: Test no-file for source #493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,10 @@ | |
""" | ||
|
||
from copy import deepcopy | ||
from typing import Dict, List, Set | ||
from typing import Dict, List, Set, Optional | ||
import ast | ||
import collections | ||
import functools | ||
import importlib | ||
import inspect | ||
import os | ||
|
@@ -111,7 +112,15 @@ | |
IGNORE_COMMENT_PATTERN = re.compile("(?:.* numpydoc ignore[=|:] ?)(.+)") | ||
|
||
|
||
def extract_ignore_validation_comments(filepath: os.PathLike) -> Dict[int, List[str]]: | ||
# This function gets called once per function/method to be validated. | ||
# We have to balance memory usage with performance here. It shouldn't be too | ||
# bad to store these `dict`s (they should be rare), but to be safe let's keep | ||
# the limit low-ish. This was set by looking at scipy, numpy, matplotlib, | ||
# and pandas and they had between ~500 and ~1300 .py files as of 2023-08-16. | ||
@functools.lru_cache(maxsize=2000) | ||
def extract_ignore_validation_comments( | ||
filepath: Optional[os.PathLike], | ||
) -> Dict[int, List[str]]: | ||
""" | ||
Extract inline comments indicating certain validation checks should be ignored. | ||
|
||
|
@@ -125,8 +134,12 @@ def extract_ignore_validation_comments(filepath: os.PathLike) -> Dict[int, List[ | |
dict[int, list[str]] | ||
Mapping of line number to a list of checks to ignore. | ||
""" | ||
with open(filepath) as file: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would tweak this slightly. numpydoc_ignore_comments = {}
try:
with open(filepath) as file:
last_declaration = 1
declarations = ["def", "class"]
for token in tokenize.generate_tokens(file.readline):
if token.type == tokenize.NAME and token.string in declarations:
last_declaration = token.start[0]
if token.type == tokenize.COMMENT:
match = re.match(IGNORE_COMMENT_PATTERN, token.string)
if match:
rules = match.group(1).split(",")
numpydoc_ignore_comments[last_declaration] = rules
except (OSError, TypeError): # can be None, nonexistent, or unreadable
pass
return numpydoc_ignore_comments There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually prefer the current approach as I always try to limit the scope of |
||
numpydoc_ignore_comments = {} | ||
numpydoc_ignore_comments = {} | ||
try: | ||
file = open(filepath) | ||
except (OSError, TypeError): # can be None, nonexistent, or unreadable | ||
return numpydoc_ignore_comments | ||
with file: | ||
last_declaration = 1 | ||
declarations = ["def", "class"] | ||
for token in tokenize.generate_tokens(file.readline): | ||
|
Uh oh!
There was an error while loading. Please reload this page.