mirror of https://github.com/scrapy/scrapy.git
utility for showing a warning when a class is subclassed
This commit is contained in:
parent
74433a17e7
commit
439a141aae
|
|
@ -9,3 +9,17 @@ def attribute(obj, oldattr, newattr, version='0.12'):
|
|||
warnings.warn("%s.%s attribute is deprecated and will be no longer supported "
|
||||
"in Scrapy %s, use %s.%s attribute instead" % \
|
||||
(cname, oldattr, version, cname, newattr), ScrapyDeprecationWarning, stacklevel=3)
|
||||
|
||||
|
||||
def warn_when_subclassed(mro_len, message, category=ScrapyDeprecationWarning):
|
||||
"""
|
||||
Return a metaclass that causes classes to
|
||||
issue a warning when they are subclassed.
|
||||
"""
|
||||
class Metaclass(type):
|
||||
def __init__(cls, name, bases, clsdict):
|
||||
if len(cls.mro()) > mro_len:
|
||||
warnings.warn(message, category, stacklevel=2)
|
||||
super(Metaclass, cls).__init__(name, bases, clsdict)
|
||||
return Metaclass
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue