Lines Matching defs:the

7 Among other things, the module includes the following:
29 import re as stdlib_re # Avoid confusion with the re we export.
154 # The pseudo-submodules 're' and 'io' are part of the public
169 """Check that the argument is a type, and return it (internal helper).
178 We append the repr() of the actual value (truncated to 100 chars).
209 The canonical representation for a Callable's __args__ flattens the
215 As a result, if we need to reconstruct the Callable from its __args__,
225 """Return the repr() of an object, special-casing types (internal helper).
227 If obj is a type, we return a shorter version than the default
228 type.__repr__, based on the module and qualified name, which is
298 # Weed out strict duplicates, preserving the first of each occurrence.
364 """Evaluate all forward references in the given type t.
366 For use of globalns and localns see the docstring for get_type_hints().
507 Note that all the above statements are true from the point of view of
530 has no values. Starting in Python 3.11, the Never type should
531 be used for this concept instead. Type checkers should treat the two
537 # separately so that type checkers can distinguish between the two
566 """Used to spell the type of "self" in classes.
657 On Python 3.10 and higher, the | operator
659 X | Y means the same thing to the type checker as Union[X, Y].
677 - When comparing unions, the argument order is ignored, e.g.::
708 This form can be used to indicate to type checkers that the corresponding
709 variable or function parameter has a value equivalent to the provided
748 It's invalid when used anywhere except as in the example above.
759 transforms the parameters of a callable.
784 ``TypeGuard`` can be used to annotate the return type of a user-defined
791 conditional code flow and applying the narrowing to a block of code. The
798 Using ``-> TypeGuard`` tells the static type checker that for a given
802 2. If the return value is ``True``, the type of its argument
803 is the type inside ``TypeGuard``.
819 narrowing ``List[object]`` to ``List[str]`` even though the latter is not
820 a subtype of the former, since ``List`` is invariant. The responsibility of
821 writing type-safe type guards is left to the user.
844 # do the unpacking manually.
933 This is used by TypeVar and ParamSpec, which both employ the notions of
976 Type variables exist primarily for the benefit of static type
977 checkers. They serve as the parameters for generic types as well
986 '''Return the longest of two strings.'''
989 The latter example's signature is essentially the overloading
991 that if the arguments are instances of some subclass of str,
992 the return type is still plain str.
1170 Parameter specification variables exist primarily for the benefit of static
1171 type checkers. They are used to forward the parameter types of one
1174 or as the first argument to ``Callable``, or as parameters for user-defined
1233 # Convert lists to tuples to help other libraries cache the results.
1242 """The central part of the internal API.
1247 have 'name' always set. If 'inst' is False, then the alias can't be instantiated;
1314 # e.g., Union[T, int].__origin__ == Union, or the non-generic version of
1315 # the type.
1421 # In the example above, this would be {T3: str}
1459 # Consider the following `Callable`.
1471 # Consider the following `_GenericAlias`, `B`:
1476 # The `new_arg` corresponding to `T` will be `float`, and the
1508 # To ensure the repr is eval-able.
1541 # _nparams is the number of accepted parameters, e.g. 0 for Hashable,
1715 The type unpack operator takes the child types from some container type,
1725 # `TypeVar`s, which the `Unpack` is 'pulling out' directly into the
1731 From Python 3.11, this can also be done using the `*` operator::
1737 everything the runtime allows may be accepted by static type checkers.
1800 At least, parameterizing a generic class is the *main* thing this method
1805 classes in the first place with `class Foo(Generic[T]): ...`.
1899 This includes names actually defined in the class dictionary, as well
1930 # The first instantiation of the subclass will call `_no_init_or_replace_init` which
1931 # searches for a proper new `__init__` in the MRO. The new `__init__`
1932 # replaces the subclass' old `__init__` (ie `_no_init_or_replace_init`). Subsequent
1933 # instantiation of the protocol subclass will thus use the new
1958 issubclass() on the whole MRO of a user class, which may contain protocols.
1974 # the lack of __instancehook__.
2023 only the presence of given attributes, ignoring their type signatures.
2042 # Set (or override) the protocol subclass hook.
2062 # Second, perform the actual structural compatibility check.
2065 # Check if the members appears in the class dictionary...
2103 At its core 'Annotated[t, dec1, dec2, ...]' is an alias for the type 't'
2105 Instantiating is the same as instantiating the underlying type; binding
2106 it to types is also the same.
2152 Example: Annotated[int, runtime_check.Unsigned] indicates to the
2162 - Access the metadata via the ``__metadata__`` attribute::
2170 - Instantiating an annotated type is equivalent to instantiating the
2236 Warning: this will check only the presence of the required methods,
2249 This returns the value unchanged. To the type checker this
2250 signals that the return value has the designated type, but at
2258 """Ask a static type checker to confirm that the value is of the given type.
2260 At runtime this does nothing: it returns the first argument unchanged with no
2261 checks or side effects, no matter the actual type of the argument.
2264 emits an error if the value is not of the specified type::
2281 This is often the same as obj.__annotations__, but it handles
2289 TypeError is raised if the argument is not of a type that can contain
2293 BEWARE -- the behavior of globalns and localns is counterintuitive
2297 - If no dict arguments are passed, an attempt is made to use the
2298 globals from obj (or the respective module's globals for classes),
2299 and these are also used as the locals. If the object does not appear
2300 to have globals, an empty dictionary is used. For classes, the search
2325 # get_type_hints only evaluated the globalns of
2327 # the globalns and localns order so that eval() looks into
2345 # Find globalns for the unwrapped object.
2378 """Strip the annotations from a given type."""
2403 """Get the unsubscripted version of a type.
2504 This mutates the function(s) or class(es) in place.
2534 """Decorator to give another decorator the @no_type_check effect.
2536 This wraps the decorator with something that wraps the decorated
2564 In a stub file, place two or more stub definitions for the same
2574 In a non-stub file (i.e. a regular .py file), do the same but
2587 The overloads for a function can be retrieved at runtime using the
2613 """Clear all overloads in the registry."""
2620 Use this decorator to indicate to type checkers that the decorated
2640 attempts to set the ``__final__`` attribute to ``True`` on the decorated
2646 # Skip the attribute silently if it is not writable.
2647 # AttributeError happens if the object has __slots__ or a
2653 # Some unconstrained type variables. These are used by the container types.
2690 values: the argument list and the return type.
2699 # NOTE: Mapping is only covariant in the value type.
2710 Tuple[X, Y] is the cross-product type of X and Y.
2740 For example, suppose we have the following classes::
2748 User and returns an instance of the corresponding class::
2753 # (Here we could write the user object to a database)
2758 At this point the type checker knows that joe has type BasicUser.
2908 the _fields attribute, which is part of the namedtuple API.)
3019 The type info can be accessed via the Point2D.__annotations__ dict, and
3020 the Point2D.__required_keys__ and Point2D.__optional_keys__ frozensets.
3032 This means that a Point2D TypedDict can have any of the keys omitted. A type
3033 checker is only expected to support a literal False or True as the value of
3034 the total argument. True is the default, and makes all items defined in the
3041 x: int # the "x" key must always be present (Required is the default)
3042 y: NotRequired[int] # the "y" key can be omitted
3184 This is an abstract, generic version of the return of open().
3186 NOTE: This does not distinguish between the different possible
3189 below capture the distinctions between text vs. binary, which is
3190 pervasive in the interface; however we currently do not offer a
3191 way to track the other distinctions in the type system.
3281 """Typed version of the return of open() in binary mode."""
3295 """Typed version of the return of open() in text mode."""
3370 """Reveal the inferred type of a variable.
3373 it will emit the inferred type of the argument::
3381 At runtime, the function prints the runtime type of the
3441 - ``eq_default`` indicates whether the ``eq`` parameter is assumed to be
3442 ``True`` or ``False`` if it is omitted by the caller.
3443 - ``order_default`` indicates whether the ``order`` parameter is
3444 assumed to be True or False if it is omitted by the caller.
3445 - ``kw_only_default`` indicates whether the ``kw_only`` parameter is
3446 assumed to be True or False if it is omitted by the caller.
3452 At runtime, this decorator records its arguments in the
3453 ``__dataclass_transform__`` attribute on the decorated object.