@@ -1348,31 +1348,32 @@ def numeric_type(self, value: object, n: AST) -> Type:
1348
1348
column = getattr (n , 'col_offset' , - 1 ),
1349
1349
)
1350
1350
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.
1371
1354
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 )
1376
1377
1377
1378
# Subscript(expr value, slice slice, expr_context ctx)
1378
1379
def visit_Subscript (self , n : ast3 .Subscript ) -> Type :
0 commit comments