module documentation

Some helpers for deprecation messages

Function attribute Undocumented
Function create_deprecated_class Return a "deprecated" class that causes its subclasses to issue a warning. Subclasses of ``new_class`` are considered subclasses of this class. It also warns when the deprecated class is instantiated, but do not when its subclasses are instantiated.
Function method_is_overridden Return True if a method named ``method_name`` of a ``base_class`` is overridden in a ``subclass``.
Function update_classpath Update a deprecated path from an object with its new location
Constant DEPRECATION_RULES Undocumented
Function _clspath Undocumented
def attribute(obj, oldattr, newattr, version='0.12'): (source)

Undocumented

def create_deprecated_class(name, new_class, clsdict=None, warn_category=ScrapyDeprecationWarning, warn_once=True, old_class_path=None, new_class_path=None, subclass_warn_message='{cls} inherits from deprecated class {old}, please inherit from {new}.', instance_warn_message='{cls} is deprecated, instantiate {new} instead.'): (source)

Return a "deprecated" class that causes its subclasses to issue a warning. Subclasses of ``new_class`` are considered subclasses of this class. It also warns when the deprecated class is instantiated, but do not when its subclasses are instantiated. It can be used to rename a base class in a library. For example, if we have class OldName(SomeClass): # ... and we want to rename it to NewName, we can do the following:: class NewName(SomeClass): # ... OldName = create_deprecated_class('OldName', NewName) Then, if user class inherits from OldName, warning is issued. Also, if some code uses ``issubclass(sub, OldName)`` or ``isinstance(sub(), OldName)`` checks they'll still return True if sub is a subclass of NewName instead of OldName.

def method_is_overridden(subclass, base_class, method_name): (source)

Return True if a method named ``method_name`` of a ``base_class`` is overridden in a ``subclass``. >>> class Base: ... def foo(self): ... pass >>> class Sub1(Base): ... pass >>> class Sub2(Base): ... def foo(self): ... pass >>> class Sub3(Sub1): ... def foo(self): ... pass >>> class Sub4(Sub2): ... pass >>> method_is_overridden(Sub1, Base, 'foo') False >>> method_is_overridden(Sub2, Base, 'foo') True >>> method_is_overridden(Sub3, Base, 'foo') True >>> method_is_overridden(Sub4, Base, 'foo') True

def update_classpath(path): (source)

Update a deprecated path from an object with its new location

DEPRECATION_RULES: List[Tuple[str, str]] = (source)

Undocumented

Value
[]
def _clspath(cls, forced=None): (source)

Undocumented