Skip to content

Commit d3ebf5d

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 573125e commit d3ebf5d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

mypy/fastparse.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ def ast3_parse(
141141
source: str | bytes, filename: str, mode: str, feature_version: int = PY_MINOR_VERSION
142142
) -> AST:
143143
"""This function is just a convenience wrapper around ast.parse, with default flags useful to Mypy.
144-
It also incorporates a hack to accomodate `# mypy: ignore` comments, which are treated by mypy as `# type: ignore` comments."""
144+
It also incorporates a hack to accomodate `# mypy: ignore` comments, which are treated by mypy as `# type: ignore` comments.
145+
"""
145146
# Hack to support "mypy: ignore" comments until the builtin compile function changes to allow us to detect it otherwise:
146147
# (Note: completely distinct from https://mypy.readthedocs.io/en/stable/inline_config.html ; see also, util.get_mypy_comments in this codebase)
147148

@@ -150,15 +151,19 @@ def ast3_parse(
150151
# Note that the functions in this module are only designed to parse syntactically valid Python code (code that does not raise when parsed using ast.parse()). The behavior of the functions in this module is **undefined** when providing invalid Python code and it can change at any point.
151152
# So, we cannot rely on roundtrip behavior in tokenize iff ast.parse would throw when given `source`.
152153
# The simplest way to deal with that is just to call ast.parse twice, once before and once after. So, we do that.
153-
p = lambda: ast3.parse(source, filename, mode, type_comments=True, feature_version=feature_version)
154-
p() # Call to assure syntactic validity (will throw an exception otherwise, exiting this function).
154+
p = lambda: ast3.parse(
155+
source, filename, mode, type_comments=True, feature_version=feature_version
156+
)
157+
p() # Call to assure syntactic validity (will throw an exception otherwise, exiting this function).
155158
if isinstance(source, str):
156159
tokens = tokenize.generate_tokens(io.StringIO(source).readline)
157160
to_find, to_replace = r"#\s*mypy:\s*ignore(?![-_])", "# type: ignore"
158161
else:
159162
tokens = tokenize.tokenize(io.BytesIO(source).readline)
160163
to_find, to_replace = rb"#\s*mypy:\s*ignore(?![-_])", b"# type: ignore"
161-
source = tokenize.untokenize((t, re.sub(to_find, to_replace, s) if t == tokenize.COMMENT else s) for t, s, *_ in tokens)
164+
source = tokenize.untokenize(
165+
(t, re.sub(to_find, to_replace, s) if t == tokenize.COMMENT else s) for t, s, *_ in tokens
166+
)
162167
return p()
163168

164169

0 commit comments

Comments
 (0)