:func:`abstractmethod`, making this decorator redundant.
-.. decorator:: abstractproperty(fget=None, fset=None, fdel=None, doc=None)
+.. decorator:: abstractproperty
A subclass of the built-in :func:`property`, indicating an abstract
property.
base 16). :exc:`ValueError` will be raised if *i* is outside that range.
-.. function:: classmethod(function)
+.. decorator:: classmethod
- Return a class method for *function*.
+ Transform a method into a class method.
A class method receives the class as implicit first argument, just like an
instance method receives the instance. To declare a class method, use this
For sorting examples and a brief sorting tutorial, see :ref:`sortinghowto`.
-.. function:: staticmethod(function)
+.. decorator:: staticmethod
- Return a static method for *function*.
+ Transform a method into a static method.
A static method does not receive an implicit first argument. To declare a static
method, use this idiom::
:func:`classmethod` for a variant that is useful for creating alternate class
constructors.
+ Like all decorators, it is also possible to call ``staticmethod`` as
+ a regular function and do something with its result. This is needed
+ in some cases where you need a reference to a function from a class
+ body and you want to avoid the automatic transformation to instance
+ method. For these cases, use this idiom:
+
+ class C:
+ builtin_open = staticmethod(open)
+
For more information on static methods, consult the documentation on the
standard type hierarchy in :ref:`types`.
- .. index::
- single: string; str() (built-in function)
+.. index::
+ single: string; str() (built-in function)
.. _func-str:
.. class:: str(object='')
return value
-.. decorator:: singledispatch(default)
+.. decorator:: singledispatch
- Transforms a function into a :term:`single-dispatch <single
+ Transform a function into a :term:`single-dispatch <single
dispatch>` :term:`generic function`.
To define a generic function, decorate it with the ``@singledispatch``
otherwise.
-.. decorator:: skip_unless_symlink()
+.. decorator:: skip_unless_symlink
A decorator for running tests that require support for symbolic links.
See :pep:`484` for details and comparison with other typing semantics.
-.. decorator:: no_type_check(arg)
+.. decorator:: no_type_check
Decorator to indicate that annotations are not type hints.
- The argument must be a class or function; if it is a class, it
+ This works as class or function :term:`decorator`. With a class, it
applies recursively to all methods defined in that class (but not
to methods defined in its superclasses or subclasses).
This mutates the function(s) in place.
-.. decorator:: no_type_check_decorator(decorator)
+.. decorator:: no_type_check_decorator
Decorator to give another decorator the :func:`no_type_check` effect.
def test_meta_no_type_check(self):
@no_type_check_decorator
- def magic_decorator(deco):
- return deco
+ def magic_decorator(func):
+ return func
self.assertEqual(magic_decorator.__name__, 'magic_decorator')