Skip to content

Commit 44242fb

Browse files
make the re.sub take str or bytes, like the function signature
1 parent 7831c70 commit 44242fb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

mypy/fastparse.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ def ast3_parse(
140140
) -> AST:
141141
# Hack to support "mypy: ignore" comments until the builtin compile function changes to allow us to detect it otherwise:
142142
# (does not apply at the start of the line to avoid conflicting with mypy file configuration comments https://mypy.readthedocs.io/en/stable/inline_config.html ; see also, util.get_mypy_comments in this codebase)
143-
source = re.sub(r"(?<!^)#\s*mypy:\s*ignore", "# type: ignore", source)
143+
if isinstance(source, str):
144+
source = re.sub(r"(?<!^)#\s*mypy:\s*ignore", "# type: ignore", source)
145+
else:
146+
source = re.sub(rb"(?<!^)#\s*mypy:\s*ignore", b"# type: ignore", source)
144147
return ast3.parse(
145148
source,
146149
filename,

0 commit comments

Comments
 (0)