@@ -465,7 +465,8 @@ def _deprecate_method_override(method, obj, *, allow_empty=False, **kwargs):
465465 can always use ``__class__`` to refer to the class that is currently
466466 being defined.
467467 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.
469470 allow_empty : bool, default: False
470471 Whether to allow overrides by "empty" methods without emitting a
471472 warning.
@@ -478,15 +479,19 @@ def empty(): pass
478479 def empty_with_docstring (): """doc"""
479480
480481 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
483488 and (not allow_empty
484- or (getattr (getattr (bound_method , "__code__" , None ),
489+ or (getattr (getattr (bound_child , "__code__" , None ),
485490 "co_code" , None )
486491 not in [empty .__code__ .co_code ,
487492 empty_with_docstring .__code__ .co_code ]))):
488493 warn_deprecated (** {"name" : name , "obj_type" : "method" , ** kwargs })
489- return bound_method
494+ return bound_child
490495 return None
491496
492497
0 commit comments