Skip to content

Commit 83e5e4c

Browse files
authored
Fix mypyc build by removing conditional method definition in fastparse (#6554)
Remove the conditional method definition added in #6539, which mypyc doesn't support.
1 parent 5d52eac commit 83e5e4c

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

mypy/fastparse.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,31 +1348,32 @@ def numeric_type(self, value: object, n: AST) -> Type:
13481348
column=getattr(n, 'col_offset', -1),
13491349
)
13501350

1351-
if sys.version_info < (3, 8):
1352-
# Using typed_ast
1353-
1354-
# Num(number n)
1355-
def visit_Num(self, n: Num) -> Type:
1356-
return self.numeric_type(n.n, n)
1357-
1358-
# Str(string s)
1359-
def visit_Str(self, n: Str) -> Type:
1360-
# Note: we transform these fallback types into the correct types in
1361-
# 'typeanal.py' -- specifically in the named_type_with_normalized_str method.
1362-
# If we're analyzing Python 3, that function will translate 'builtins.unicode'
1363-
# into 'builtins.str'. In contrast, if we're analyzing Python 2 code, we'll
1364-
# translate 'builtins.bytes' in the method below into 'builtins.str'.
1365-
if 'u' in n.kind or self.assume_str_is_unicode:
1366-
return parse_type_string(n.s, 'builtins.unicode', self.line, n.col_offset,
1367-
assume_str_is_unicode=self.assume_str_is_unicode)
1368-
else:
1369-
return parse_type_string(n.s, 'builtins.str', self.line, n.col_offset,
1370-
assume_str_is_unicode=self.assume_str_is_unicode)
1351+
# These next three methods are only used if we are on python <
1352+
# 3.8, using typed_ast. They are defined unconditionally because
1353+
# mypyc can't handle conditional method definitions.
13711354

1372-
# Bytes(bytes s)
1373-
def visit_Bytes(self, n: Bytes) -> Type:
1374-
contents = bytes_to_human_readable_repr(n.s)
1375-
return RawExpressionType(contents, 'builtins.bytes', self.line, column=n.col_offset)
1355+
# Num(number n)
1356+
def visit_Num(self, n: Num) -> Type:
1357+
return self.numeric_type(n.n, n)
1358+
1359+
# Str(string s)
1360+
def visit_Str(self, n: Str) -> Type:
1361+
# Note: we transform these fallback types into the correct types in
1362+
# 'typeanal.py' -- specifically in the named_type_with_normalized_str method.
1363+
# If we're analyzing Python 3, that function will translate 'builtins.unicode'
1364+
# into 'builtins.str'. In contrast, if we're analyzing Python 2 code, we'll
1365+
# translate 'builtins.bytes' in the method below into 'builtins.str'.
1366+
if 'u' in n.kind or self.assume_str_is_unicode:
1367+
return parse_type_string(n.s, 'builtins.unicode', self.line, n.col_offset,
1368+
assume_str_is_unicode=self.assume_str_is_unicode)
1369+
else:
1370+
return parse_type_string(n.s, 'builtins.str', self.line, n.col_offset,
1371+
assume_str_is_unicode=self.assume_str_is_unicode)
1372+
1373+
# Bytes(bytes s)
1374+
def visit_Bytes(self, n: Bytes) -> Type:
1375+
contents = bytes_to_human_readable_repr(n.s)
1376+
return RawExpressionType(contents, 'builtins.bytes', self.line, column=n.col_offset)
13761377

13771378
# Subscript(expr value, slice slice, expr_context ctx)
13781379
def visit_Subscript(self, n: ast3.Subscript) -> Type:

0 commit comments

Comments
 (0)