@@ -469,10 +469,6 @@ def check_first_pass(self) -> None:
469
469
seq_str = self .named_generic_type (
470
470
"typing.Sequence" , [self .named_type ("builtins.str" )]
471
471
)
472
- if self .options .python_version [0 ] < 3 :
473
- seq_str = self .named_generic_type (
474
- "typing.Sequence" , [self .named_type ("builtins.unicode" )]
475
- )
476
472
if not is_subtype (all_ .type , seq_str ):
477
473
str_seq_s , all_s = format_type_distinctly (seq_str , all_ .type )
478
474
self .fail (
@@ -1093,18 +1089,6 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: Optional[str])
1093
1089
if not self .is_generator_return_type (typ .ret_type , defn .is_coroutine ):
1094
1090
self .fail (message_registry .INVALID_RETURN_TYPE_FOR_GENERATOR , typ )
1095
1091
1096
- # Python 2 generators aren't allowed to return values.
1097
- orig_ret_type = get_proper_type (typ .ret_type )
1098
- if (
1099
- self .options .python_version [0 ] == 2
1100
- and isinstance (orig_ret_type , Instance )
1101
- and orig_ret_type .type .fullname == "typing.Generator"
1102
- ):
1103
- if not isinstance (
1104
- get_proper_type (orig_ret_type .args [2 ]), (NoneType , AnyType )
1105
- ):
1106
- self .fail (message_registry .INVALID_GENERATOR_RETURN_ITEM_TYPE , typ )
1107
-
1108
1092
# Fix the type if decorated with `@types.coroutine` or `@asyncio.coroutine`.
1109
1093
if defn .is_awaitable_coroutine :
1110
1094
# Update the return type to AwaitableGenerator.
@@ -1145,7 +1129,6 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: Optional[str])
1145
1129
ref_type = mypy .types .TypeType .make_normalized (ref_type )
1146
1130
erased = get_proper_type (erase_to_bound (arg_type ))
1147
1131
if not is_subtype (ref_type , erased , ignore_type_params = True ):
1148
- note = None
1149
1132
if (
1150
1133
isinstance (erased , Instance )
1151
1134
and erased .type .is_protocol
@@ -1158,23 +1141,13 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: Optional[str])
1158
1141
# the consistency check will be performed at call sites.
1159
1142
msg = None
1160
1143
elif typ .arg_names [i ] in {"self" , "cls" }:
1161
- if (
1162
- self .options .python_version [0 ] < 3
1163
- and is_same_type (erased , arg_type )
1164
- and not isclass
1165
- ):
1166
- msg = message_registry .INVALID_SELF_TYPE_OR_EXTRA_ARG
1167
- note = "(Hint: typically annotations omit the type for self)"
1168
- else :
1169
- msg = message_registry .ERASED_SELF_TYPE_NOT_SUPERTYPE .format (
1170
- erased , ref_type
1171
- )
1144
+ msg = message_registry .ERASED_SELF_TYPE_NOT_SUPERTYPE .format (
1145
+ erased , ref_type
1146
+ )
1172
1147
else :
1173
1148
msg = message_registry .MISSING_OR_INVALID_SELF_TYPE
1174
1149
if msg :
1175
1150
self .fail (msg , defn )
1176
- if note :
1177
- self .note (note , defn )
1178
1151
elif isinstance (arg_type , TypeVarType ):
1179
1152
# Refuse covariant parameter type variables
1180
1153
# TODO: check recursively for inner type variables
@@ -1287,16 +1260,10 @@ def check_default_args(self, item: FuncItem, body_is_trivial: bool) -> None:
1287
1260
)
1288
1261
1289
1262
def is_forward_op_method (self , method_name : str ) -> bool :
1290
- if self .options .python_version [0 ] == 2 and method_name == "__div__" :
1291
- return True
1292
- else :
1293
- return method_name in operators .reverse_op_methods
1263
+ return method_name in operators .reverse_op_methods
1294
1264
1295
1265
def is_reverse_op_method (self , method_name : str ) -> bool :
1296
- if self .options .python_version [0 ] == 2 and method_name == "__rdiv__" :
1297
- return True
1298
- else :
1299
- return method_name in operators .reverse_op_method_set
1266
+ return method_name in operators .reverse_op_method_set
1300
1267
1301
1268
def check_for_missing_annotations (self , fdef : FuncItem ) -> None :
1302
1269
# Check for functions with unspecified/not fully specified types.
@@ -1459,10 +1426,7 @@ def check_reverse_op_method(
1459
1426
)
1460
1427
assert len (reverse_type .arg_types ) >= 2
1461
1428
1462
- if self .options .python_version [0 ] == 2 and reverse_name == "__rdiv__" :
1463
- forward_name = "__div__"
1464
- else :
1465
- forward_name = operators .normal_from_reverse_op [reverse_name ]
1429
+ forward_name = operators .normal_from_reverse_op [reverse_name ]
1466
1430
forward_inst = get_proper_type (reverse_type .arg_types [1 ])
1467
1431
if isinstance (forward_inst , TypeVarType ):
1468
1432
forward_inst = get_proper_type (forward_inst .upper_bound )
@@ -4198,20 +4162,10 @@ def visit_try_without_finally(self, s: TryStmt, try_frame: bool) -> None:
4198
4162
self .accept (s .handlers [i ])
4199
4163
var = s .vars [i ]
4200
4164
if var :
4201
- # Exception variables are deleted in python 3 but not python 2.
4202
- # But, since it's bad form in python 2 and the type checking
4203
- # wouldn't work very well, we delete it anyway.
4204
-
4165
+ # Exception variables are deleted.
4205
4166
# Unfortunately, this doesn't let us detect usage before the
4206
4167
# try/except block.
4207
- if self .options .python_version [0 ] >= 3 :
4208
- source = var .name
4209
- else :
4210
- source = (
4211
- '(exception variable "{}", which we do not '
4212
- "accept outside except: blocks even in "
4213
- "python 2)" .format (var .name )
4214
- )
4168
+ source = var .name
4215
4169
if isinstance (var .node , Var ):
4216
4170
var .node .type = DeletedType (source = source )
4217
4171
self .binder .cleanse (var )
@@ -4302,11 +4256,7 @@ def analyze_iterable_item_type(self, expr: Expression) -> Tuple[Type, Type]:
4302
4256
return iterator , joined
4303
4257
else :
4304
4258
# Non-tuple iterable.
4305
- if self .options .python_version [0 ] >= 3 :
4306
- nextmethod = "__next__"
4307
- else :
4308
- nextmethod = "next"
4309
- return iterator , echk .check_method_call_by_name (nextmethod , iterator , [], [], expr )[0 ]
4259
+ return iterator , echk .check_method_call_by_name ("__next__" , iterator , [], [], expr )[0 ]
4310
4260
4311
4261
def analyze_container_item_type (self , typ : Type ) -> Optional [Type ]:
4312
4262
"""Check if a type is a nominal container of a union of such.
0 commit comments