@@ -1221,22 +1221,32 @@ def check_method_override_for_base_with_name(
1221
1221
# Construct the type of the overriding method.
1222
1222
if isinstance (defn , FuncBase ):
1223
1223
typ = self .function_type (defn ) # type: Type
1224
+ override_class_or_static = defn .is_class or defn .is_static
1224
1225
else :
1225
1226
assert defn .var .is_ready
1226
1227
assert defn .var .type is not None
1227
1228
typ = defn .var .type
1229
+ override_class_or_static = defn .func .is_class or defn .func .is_static
1228
1230
if isinstance (typ , FunctionLike ) and not is_static (context ):
1229
1231
typ = bind_self (typ , self .scope .active_self_type ())
1230
1232
# Map the overridden method type to subtype context so that
1231
1233
# it can be checked for compatibility.
1232
1234
original_type = base_attr .type
1235
+ original_node = base_attr .node
1233
1236
if original_type is None :
1234
- if isinstance (base_attr . node , FuncDef ):
1235
- original_type = self .function_type (base_attr . node )
1236
- elif isinstance (base_attr . node , Decorator ):
1237
- original_type = self .function_type (base_attr . node .func )
1237
+ if isinstance (original_node , FuncBase ):
1238
+ original_type = self .function_type (original_node )
1239
+ elif isinstance (original_node , Decorator ):
1240
+ original_type = self .function_type (original_node .func )
1238
1241
else :
1239
1242
assert False , str (base_attr .node )
1243
+ if isinstance (original_node , FuncBase ):
1244
+ original_class_or_static = original_node .is_class or original_node .is_static
1245
+ elif isinstance (original_node , Decorator ):
1246
+ fdef = original_node .func
1247
+ original_class_or_static = fdef .is_class or fdef .is_static
1248
+ else :
1249
+ original_class_or_static = False # a variable can't be class or static
1240
1250
if isinstance (original_type , AnyType ) or isinstance (typ , AnyType ):
1241
1251
pass
1242
1252
elif isinstance (original_type , FunctionLike ) and isinstance (typ , FunctionLike ):
@@ -1253,6 +1263,8 @@ def check_method_override_for_base_with_name(
1253
1263
defn .name (),
1254
1264
name ,
1255
1265
base .name (),
1266
+ original_class_or_static ,
1267
+ override_class_or_static ,
1256
1268
context )
1257
1269
elif is_equivalent (original_type , typ ):
1258
1270
# Assume invariance for a non-callable attribute here. Note
@@ -1267,6 +1279,8 @@ def check_method_override_for_base_with_name(
1267
1279
1268
1280
def check_override (self , override : FunctionLike , original : FunctionLike ,
1269
1281
name : str , name_in_super : str , supertype : str ,
1282
+ original_class_or_static : bool ,
1283
+ override_class_or_static : bool ,
1270
1284
node : Context ) -> None :
1271
1285
"""Check a method override with given signatures.
1272
1286
@@ -1289,8 +1303,7 @@ def check_override(self, override: FunctionLike, original: FunctionLike,
1289
1303
fail = True
1290
1304
1291
1305
if isinstance (original , FunctionLike ) and isinstance (override , FunctionLike ):
1292
- if ((original .is_classmethod () or original .is_staticmethod ()) and
1293
- not (override .is_classmethod () or override .is_staticmethod ())):
1306
+ if original_class_or_static and not override_class_or_static :
1294
1307
fail = True
1295
1308
1296
1309
if fail :
0 commit comments