@@ -1321,7 +1321,8 @@ def check_typevar_name(self, call: CallExpr, name: str, context: Context) -> boo
1321
1321
if len (call .args ) < 1 :
1322
1322
self .fail ("Too few arguments for TypeVar()" , context )
1323
1323
return False
1324
- if not isinstance (call .args [0 ], (StrExpr , BytesExpr )) or not call .arg_kinds [0 ] == ARG_POS :
1324
+ if (not isinstance (call .args [0 ], (StrExpr , BytesExpr , UnicodeExpr ))
1325
+ or not call .arg_kinds [0 ] == ARG_POS ):
1325
1326
self .fail ("TypeVar() expects a string literal as first argument" , context )
1326
1327
return False
1327
1328
if cast (StrExpr , call .args [0 ]).value != name :
@@ -1467,13 +1468,14 @@ def parse_namedtuple_args(self, call: CallExpr,
1467
1468
return self .fail_namedtuple_arg ("Too many arguments for namedtuple()" , call )
1468
1469
if call .arg_kinds != [ARG_POS , ARG_POS ]:
1469
1470
return self .fail_namedtuple_arg ("Unexpected arguments to namedtuple()" , call )
1470
- if not isinstance (args [0 ], (StrExpr , BytesExpr )):
1471
+ if not isinstance (args [0 ], (StrExpr , BytesExpr , UnicodeExpr )):
1471
1472
return self .fail_namedtuple_arg (
1472
1473
"namedtuple() expects a string literal as the first argument" , call )
1473
1474
types = [] # type: List[Type]
1474
1475
ok = True
1475
1476
if not isinstance (args [1 ], ListExpr ):
1476
- if fullname == 'collections.namedtuple' and isinstance (args [1 ], (StrExpr , BytesExpr )):
1477
+ if (fullname == 'collections.namedtuple'
1478
+ and isinstance (args [1 ], (StrExpr , BytesExpr , UnicodeExpr ))):
1477
1479
str_expr = cast (StrExpr , args [1 ])
1478
1480
items = str_expr .value .split ()
1479
1481
else :
@@ -1483,7 +1485,8 @@ def parse_namedtuple_args(self, call: CallExpr,
1483
1485
listexpr = args [1 ]
1484
1486
if fullname == 'collections.namedtuple' :
1485
1487
# The fields argument contains just names, with implicit Any types.
1486
- if any (not isinstance (item , (StrExpr , BytesExpr )) for item in listexpr .items ):
1488
+ if any (not isinstance (item , (StrExpr , BytesExpr , UnicodeExpr ))
1489
+ for item in listexpr .items ):
1487
1490
return self .fail_namedtuple_arg ("String literal expected as namedtuple() item" ,
1488
1491
call )
1489
1492
items = [cast (StrExpr , item ).value for item in listexpr .items ]
@@ -1504,7 +1507,7 @@ def parse_namedtuple_fields_with_types(self, nodes: List[Node],
1504
1507
return self .fail_namedtuple_arg ("Invalid NamedTuple field definition" ,
1505
1508
item )
1506
1509
name , type_node = item .items
1507
- if isinstance (name , (StrExpr , BytesExpr )):
1510
+ if isinstance (name , (StrExpr , BytesExpr , UnicodeExpr )):
1508
1511
items .append (name .value )
1509
1512
else :
1510
1513
return self .fail_namedtuple_arg ("Invalid NamedTuple() field name" , item )
0 commit comments