only warn on direct subclasses of the deprecated class

This commit is contained in:
Daniel Graña 2014-01-10 13:03:40 -02:00
parent 8c81d6c6a9
commit a97b4aa633
2 changed files with 4 additions and 1 deletions

View File

@ -31,6 +31,9 @@ class WarnWhenSubclassedTest(unittest.TestCase):
class UserClass(Deprecated):
pass
class NoWarnOnMe(UserClass):
pass
self.assertEqual(len(w), 1)
msg = w[0]
assert issubclass(msg.category, MyWarning)

View File

@ -59,7 +59,7 @@ def create_deprecated_class(name, new_class, clsdict=None,
def __init__(cls, name, bases, clsdict_):
meta = cls.__class__
old = meta.deprecated_class
if (cls is not old) and not (warn_once and meta.warned_on_subclass):
if old in bases and not (warn_once and meta.warned_on_subclass):
meta.warned_on_subclass = True
msg = subclass_warn_message.format(cls=_clspath(cls),
old=_clspath(old),