Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Module « typing » Python 3.11.3

Classe « ParamSpec »

Informations générales

Héritage

builtins.object
    _PickleUsingNameMixin
builtins.object
    _BoundVarianceMixin
builtins.object
    _Immutable
builtins.object
    _Final
        ParamSpec

Définition

class ParamSpec(_Final, _Immutable, _BoundVarianceMixin, _PickleUsingNameMixin):

help(ParamSpec)

Parameter specification variable.

    Usage::

       P = ParamSpec('P')

    Parameter specification variables exist primarily for the benefit of static
    type checkers.  They are used to forward the parameter types of one
    callable to another callable, a pattern commonly found in higher order
    functions and decorators.  They are only valid when used in ``Concatenate``,
    or as the first argument to ``Callable``, or as parameters for user-defined
    Generics.  See class Generic for more information on generic types.  An
    example for annotating a decorator::

       T = TypeVar('T')
       P = ParamSpec('P')

       def add_logging(f: Callable[P, T]) -> Callable[P, T]:
           '''A type-safe decorator to add logging to a function.'''
           def inner(*args: P.args, **kwargs: P.kwargs) -> T:
               logging.info(f'{f.__name__} was called')
               return f(*args, **kwargs)
           return inner

       @add_logging
       def add_two(x: float, y: float) -> float:
           '''Add two numbers together.'''
           return x + y

    Parameter specification variables defined with covariant=True or
    contravariant=True can be used to declare covariant or contravariant
    generic types.  These keyword arguments are valid, but their actual semantics
    are yet to be decided.  See PEP 612 for details.

    Parameter specification variables can be introspected. e.g.:

       P.__name__ == 'P'
       P.__bound__ == None
       P.__covariant__ == False
       P.__contravariant__ == False

    Note that only parameter specification variables defined in global scope can
    be pickled.
    

Constructeur(s)

Signature du constructeur Description
__init__(self, name, *, bound=None, covariant=False, contravariant=False)

Liste des propriétés

Nom de la propriétéDescription
args
kwargs

Liste des opérateurs

Opérateurs hérités de la classe _BoundVarianceMixin

__or__, __ror__

Liste des opérateurs

Opérateurs hérités de la classe object

__eq__, __ge__, __gt__, __le__, __lt__, __ne__

Liste des méthodes

Toutes les méthodes Méthodes d'instance Méthodes statiques Méthodes dépréciées
Signature de la méthodeDescription
__typing_prepare_subst__(self, alias, args)
__typing_subst__(self, arg)

Méthodes héritées de la classe _PickleUsingNameMixin

__init_subclass__, __reduce__, __subclasshook__

Méthodes héritées de la classe _BoundVarianceMixin

__init_subclass__, __repr__, __subclasshook__

Méthodes héritées de la classe _Immutable

__copy__, __deepcopy__, __init_subclass__, __subclasshook__

Méthodes héritées de la classe _Final

__init_subclass__, __subclasshook__

Méthodes héritées de la classe object

__delattr__, __dir__, __format__, __getattribute__, __getstate__, __hash__, __init_subclass__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__