|
Original |
Translation |
|
17
|
A function returning another function, usually applied as a function transformation using the ``@wrapper`` syntax. Common examples for decorators are :func:`classmethod` and :func:`staticmethod`.
|
Une fonction retournant une autre fonction, utilisé habituellement dans une transformation de fonction via la syntaxe ``@wrapper``.Les exemples habituels pour les décorateurs sont :func:`classmethod` et :func:`staticmethod`.
|
|
18
|
The decorator syntax is merely syntactic sugar, the following two function definitions are semantically equivalent::
|
La syntaxe decorator est simplement du sucre syntaxique, les définitions des deux fonctions suivantes sont sémantiquement équivalentes :
|
|
19
|
def f(...): ... f = staticmethod(f) @staticmethod def f(...): ...
|
def f(...): ... f = staticmethod(f) @staticmethod def f(...): ...
|
|
20
|
The same concept exists for classes, but is less commonly used there. See the documentation for :ref:`function definitions <function>` and :ref:`class definitions <class>` for more about decorators.
|
Quoique moins fréquemment utilisé, le même concept existe pour les classes. Consultez la documentation :ref:`définitions de fonctions <function> et :ref:`définitions de classes <class>` pour en savoir plus sur les decorators.
|
|
21
|
|
22
|
For more information about descriptors' methods, see :ref:`descriptors`.
|
Pour plus d'informations sur les méthodes des descripteurs, consultez :ref:`descriptors`.
|
|
23
|
An associative array, where arbitrary keys are mapped to values. The use of :class:`dict` closely resembles that for :class:`list`, but the keys can be any object with a :meth:`__hash__` function, not just integers. Called a hash in Perl.
|
|
|
24
|
A string literal which appears as the first expression in a class, function or module. While ignored when the suite is executed, it is recognized by the compiler and put into the :attr:`__doc__` attribute of the enclosing class, function or module. Since it is available via introspection, it is the canonical place for documentation of the object.
|
|
|
25
|
A pythonic programming style which determines an object's type by inspection of its method or attribute signature rather than by explicit relationship to some type object ("If it looks like a duck and quacks like a duck, it must be a duck.") By emphasizing interfaces rather than specific types, well-designed code improves its flexibility by allowing polymorphic substitution. Duck-typing avoids tests using :func:`type` or :func:`isinstance`. (Note, however, that duck-typing can be complemented with abstract base classes.) Instead, it typically employs :func:`hasattr` tests or :term:`EAFP` programming.
|
|
|
26
|
Easier to ask for forgiveness than permission. This common Python coding style assumes the existence of valid keys or attributes and catches exceptions if the assumption proves false. This clean and fast style is characterized by the presence of many :keyword:`try` and :keyword:`except` statements. The technique contrasts with the :term:`LBYL` style common to many other languages such as C.
|
|