@@ -968,11 +968,14 @@ def process_typevar_declaration(self, s: AssignmentStmt) -> None:
968
968
if len (call .args ) < 1 :
969
969
self .fail ("Too few arguments for TypeVar()" , s )
970
970
return
971
- if len (call .args ) > 2 :
972
- self .fail ("Too many arguments for TypeVar()" , s )
973
- return
974
- if call .arg_kinds not in ([ARG_POS ], [ARG_POS , ARG_NAMED ]):
975
- self .fail ("Unexpected arguments to TypeVar()" , s )
971
+ if call .arg_kinds != [ARG_POS ] * len (call .arg_kinds ):
972
+ if call .arg_kinds == [ARG_POS , ARG_NAMED ] and call .arg_names [1 ] == 'values' :
973
+ # Probably using obsolete syntax with values=(...). Explain the current syntax.
974
+ self .fail ("TypeVar 'values' argument not supported" , s )
975
+ self .fail ("Use TypeVar('T', t, ...) instead of TypeVar('T', values=(t, ...))" ,
976
+ s )
977
+ else :
978
+ self .fail ("Unexpected arguments to TypeVar()" , s )
976
979
return
977
980
if not isinstance (call .args [0 ], StrExpr ):
978
981
self .fail ("TypeVar() expects a string literal argument" , s )
@@ -988,19 +991,11 @@ def process_typevar_declaration(self, s: AssignmentStmt) -> None:
988
991
else :
989
992
self .fail ("Cannot redefine '%s' as a type variable" % name , s )
990
993
return
991
- if len (call .args ) == 2 :
992
- # Analyze values=(...) argument.
993
- if call .arg_names [1 ] != 'values' :
994
- self .fail ("Unexpected keyword argument '{}' to TypeVar()" .
995
- format (call .arg_names [1 ]), s )
996
- return
997
- expr = call .args [1 ]
998
- if isinstance (expr , TupleExpr ):
999
- values = self .analyze_types (expr .items )
1000
- else :
1001
- self .fail ('The values argument must be a tuple literal' , s )
1002
- return
994
+ if len (call .args ) > 1 :
995
+ # Analyze enumeration of type variable values.
996
+ values = self .analyze_types (call .args [1 :])
1003
997
else :
998
+ # Type variables can refer to an arbitrary type.
1004
999
values = []
1005
1000
# Yes, it's a valid type variable definition! Add it to the symbol table.
1006
1001
node = self .lookup (name , s )
0 commit comments