@@ -465,7 +465,8 @@ def _deprecate_method_override(method, obj, *, allow_empty=False, **kwargs):
465
465
can always use ``__class__`` to refer to the class that is currently
466
466
being defined.
467
467
obj
468
- An object of the class where *method* is defined.
468
+ Either an object of the class where *method* is defined, or a subclass
469
+ of that class.
469
470
allow_empty : bool, default: False
470
471
Whether to allow overrides by "empty" methods without emitting a
471
472
warning.
@@ -478,15 +479,19 @@ def empty(): pass
478
479
def empty_with_docstring (): """doc"""
479
480
480
481
name = method .__name__
481
- bound_method = getattr (obj , name )
482
- if (bound_method != method .__get__ (obj )
482
+ bound_child = getattr (obj , name )
483
+ bound_base = (
484
+ method # If obj is a class, then we need to use unbound methods.
485
+ if isinstance (bound_child , type (empty )) and isinstance (obj , type )
486
+ else method .__get__ (obj ))
487
+ if (bound_child != bound_base
483
488
and (not allow_empty
484
- or (getattr (getattr (bound_method , "__code__" , None ),
489
+ or (getattr (getattr (bound_child , "__code__" , None ),
485
490
"co_code" , None )
486
491
not in [empty .__code__ .co_code ,
487
492
empty_with_docstring .__code__ .co_code ]))):
488
493
warn_deprecated (** {"name" : name , "obj_type" : "method" , ** kwargs })
489
- return bound_method
494
+ return bound_child
490
495
return None
491
496
492
497
0 commit comments