Skip to content

Use TypeAlias once mypy bugs are fixed #272

Description

@github-actions

# _LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0] # noqa: Y026 # TODO: Use TypeAlias once mypy bugs are fixed

# Modified from the "builtins.pyi" file in the `_typeshed_import` directory,
# which was imported from the Typeshed (https://github.com/python/typeshed).
#
# The Typeshed is licensed under the Apache License, Version 2.0 and the
# MIT License. See the LICENSE file in the root of the repository for
# details (https://github.com/python/typeshed/blob/main/LICENSE).
#
# See "builtins.pyi" for more details.

# flake8: noqa

from __future__ import annotations

# import _ast
# import _sitebuiltins
# import _typeshed
import sys
# import types
# from _collections_abc import dict_items, dict_keys, dict_values
# from _typeshed import (
#     AnnotationForm,
#     ConvertibleToFloat,
#     ConvertibleToInt,
#     FileDescriptorOrPath,
#     OpenBinaryMode,
#     OpenBinaryModeReading,
#     OpenBinaryModeUpdating,
#     OpenBinaryModeWriting,
#     OpenTextMode,
#     ReadableBuffer,
#     SupportsAdd,
#     SupportsAiter,
#     SupportsAnext,
#     SupportsDivMod,
#     SupportsFlush,
#     SupportsIter,
#     SupportsKeysAndGetItem,
#     SupportsLenAndGetItem,
#     SupportsNext,
#     SupportsRAdd,
#     SupportsRDivMod,
#     SupportsRichComparison,
#     SupportsRichComparisonT,
#     SupportsWrite,
# )
# from collections.abc import Awaitable, Callable, Iterable, Iterator, MutableSet, Reversible, Set as AbstractSet, Sized
from collections.abc import Callable, Iterable, Iterator, Set as AbstractSet
# from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper
# from os import PathLike
# from types import CellType, CodeType, EllipsisType, GenericAlias, NotImplementedType, TracebackType

# mypy crashes if any of {ByteString, Sequence, MutableSequence, Mapping, MutableMapping}
# are imported from collections.abc in builtins.pyi
from typing import (  # noqa: Y022,UP035
    # IO,
    Any,
    # BinaryIO,
    ClassVar,
    # Concatenate,
    # Final,
    # Generic,
    # Mapping,
    # MutableMapping,
    # MutableSequence,
    # ParamSpec,
    Protocol,
    # Sequence,
    # SupportsAbs,
    SupportsBytes,
    SupportsComplex,
    SupportsFloat,
    SupportsIndex,
    TypeAlias,
    # TypeGuard,
    # TypeVar,
    # final,
    overload,
    # type_check_only,
)

# we can't import `Literal` from typing or mypy crashes: see #11247
# from typing_extensions import Literal, LiteralString, Self, TypeIs, TypeVarTuple, deprecated, disjoint_base  # noqa: Y023, UP035
from typing_extensions import Literal, LiteralString, Self, deprecated, TypeVar

if sys.version_info >= (3, 14):
    from _typeshed import AnnotateFunc

from omnipy.shared.exceptions import AssumedToBeImplementedException
from omnipy.shared.protocols._collections_abc import IsDictItems, IsDictKeys, IsDictValues
from omnipy.shared.protocols._typeshed import (ReadableBuffer, SupportsKeysAndGetItem, SupportsRichComparison, SupportsRichComparisonT)
from omnipy.shared.protocols.typing import (IsAbstractSet, IsMutableMapping, IsMutableSequence, IsMutableSet, IsItemSequence)

_T = TypeVar("_T")
# _I = TypeVar("_I", default=int)
_T_co = TypeVar("_T_co", covariant=True)
# _T_contra = TypeVar("_T_contra", contravariant=True)
# _R_co = TypeVar("_R_co", covariant=True)
_KT = TypeVar("_KT")
_VT = TypeVar("_VT")
_S = TypeVar("_S")
_T1 = TypeVar("_T1")
_T2 = TypeVar("_T2")
# _T3 = TypeVar("_T3")
# _T4 = TypeVar("_T4")
# _T5 = TypeVar("_T5")
# _SupportsNextT_co = TypeVar("_SupportsNextT_co", bound=SupportsNext[Any], covariant=True)
# _SupportsAnextT_co = TypeVar("_SupportsAnextT_co", bound=SupportsAnext[Any], covariant=True)
# _AwaitableT = TypeVar("_AwaitableT", bound=Awaitable[Any])
# _AwaitableT_co = TypeVar("_AwaitableT_co", bound=Awaitable[Any], covariant=True)
# _P = ParamSpec("_P")

# # Type variables for slice
# _StartT_co = TypeVar("_StartT_co", covariant=True, default=Any)  # slice -> slice[Any, Any, Any]
# _StopT_co = TypeVar("_StopT_co", covariant=True, default=_StartT_co)  #  slice[A] -> slice[A, A, A]
# NOTE: step could differ from start and stop, (e.g. datetime/timedelta)l
#   the default (start|stop) is chosen to cater to the most common case of int/index slices.
# # FIXME: https://github.com/python/typing/issues/213 (replace step=start|stop with step=start&stop)
# _StepT_co = TypeVar("_StepT_co", covariant=True, default=_StartT_co | _StopT_co)  #  slice[A,B] -> slice[A, B, A|B]

# @disjoint_base
# class object:
#     __doc__: str | None
#     __dict__: dict[str, Any]
#     __module__: str
#     __annotations__: dict[str, Any]
# 
#     @property
#     def __class__(self) -> type[Self]: ...
#     @__class__.setter
#     def __class__(self, type: type[Self], /) -> None: ...
# 
#     def __init__(self) -> None: ...
#     def __new__(cls) -> Self: ...
#     # N.B. `object.__setattr__` and `object.__delattr__` are heavily special-cased by type checkers.
#     # Overriding them in subclasses has different semantics, even if the override has an identical signature.
#     def __setattr__(self, name: str, value: Any, /) -> None: ...
#     def __delattr__(self, name: str, /) -> None: ...
#     def __eq__(self, value: object, /) -> bool: ...
#     def __ne__(self, value: object, /) -> bool: ...
#     def __str__(self) -> str: ...  # noqa: Y029
#     def __repr__(self) -> str: ...  # noqa: Y029
#     def __hash__(self) -> int: ...
#     def __format__(self, format_spec: str, /) -> str: ...
#     def __getattribute__(self, name: str, /) -> Any: ...
#     def __sizeof__(self) -> int: ...
#     # return type of pickle methods is rather hard to express in the current type system
#     # see #6661 and https://docs.python.org/3/library/pickle.html#object.__reduce__
#     def __reduce__(self) -> str | tuple[Any, ...]: ...
#     def __reduce_ex__(self, protocol: SupportsIndex, /) -> str | tuple[Any, ...]: ...
#     if sys.version_info >= (3, 11):
#         def __getstate__(self) -> object: ...
# 
#     def __dir__(self) -> Iterable[str]: ...
#     def __init_subclass__(cls) -> None: ...
#     @classmethod
#     def __subclasshook__(cls, subclass: type, /) -> bool: ...
# 
# @disjoint_base
# class staticmethod(Generic[_P, _R_co]):
#     __name__: str
#     __qualname__: str
#     @property
#     def __func__(self) -> Callable[_P, _R_co]: ...
#     @property
#     def __isabstractmethod__(self) -> bool: ...
#     def __init__(self, f: Callable[_P, _R_co], /) -> None: ...
# 
#     @overload
#     def __get__(self, instance: None, owner: type, /) -> Callable[_P, _R_co]: ...
#     @overload
#     def __get__(self, instance: _T, owner: type[_T] | None = None, /) -> Callable[_P, _R_co]: ...
# 
#     @property
#     def __wrapped__(self) -> Callable[_P, _R_co]: ...
#     def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R_co: ...
#     if sys.version_info >= (3, 14):
#         def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
#         __annotate__: AnnotateFunc | None
# 
# @disjoint_base
# class classmethod(Generic[_T, _P, _R_co]):
#     __name__: str
#     __qualname__: str
#     @property
#     def __func__(self) -> Callable[Concatenate[type[_T], _P], _R_co]: ...
#     @property
#     def __isabstractmethod__(self) -> bool: ...
#     def __init__(self, f: Callable[Concatenate[type[_T], _P], _R_co], /) -> None: ...
# 
#     @overload
#     def __get__(self, instance: _T, owner: type[_T] | None = None, /) -> Callable[_P, _R_co]: ...
#     @overload
#     def __get__(self, instance: None, owner: type[_T], /) -> Callable[_P, _R_co]: ...
# 
#     @property
#     def __wrapped__(self) -> Callable[Concatenate[type[_T], _P], _R_co]: ...
#     if sys.version_info >= (3, 14):
#         def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
#         __annotate__: AnnotateFunc | None
# 
# @disjoint_base
# class type:
#     # object.__base__ is None. Otherwise, it would be a type.
#     @property
#     def __base__(self) -> type | None: ...
#     __bases__: tuple[type, ...]
#     @property
#     def __basicsize__(self) -> int: ...
#     # type.__dict__ is read-only at runtime, but that can't be expressed currently.
#     # See https://github.com/python/typeshed/issues/11033 for a discussion.
#     __dict__: Final[types.MappingProxyType[str, Any]]  # type: ignore[assignment]
#     @property
#     def __dictoffset__(self) -> int: ...
#     @property
#     def __flags__(self) -> int: ...
#     @property
#     def __itemsize__(self) -> int: ...
#     __module__: str
#     @property
#     def __mro__(self) -> tuple[type, ...]: ...
#     __name__: str
#     __qualname__: str
#     @property
#     def __text_signature__(self) -> str | None: ...
#     @property
#     def __weakrefoffset__(self) -> int: ...
# 
#     @overload
#     def __init__(self, o: object, /) -> None: ...
#     @overload
#     def __init__(self, name: str, bases: tuple[type, ...], dict: dict[str, Any], /, **kwds: Any) -> None: ...
# 
#     @overload
#     def __new__(cls, o: object, /) -> type: ...
#     @overload
#     def __new__(
#         cls: type[_typeshed.Self], name: str, bases: tuple[type, ...], namespace: dict[str, Any], /, **kwds: Any
#     ) -> _typeshed.Self: ...
# 
#     def __call__(self, *args: Any, **kwds: Any) -> Any: ...
#     def __subclasses__(self: _typeshed.Self) -> list[_typeshed.Self]: ...
#     # Note: the documentation doesn't specify what the return type is, the standard
#     # implementation seems to be returning a list.
#     def mro(self) -> list[type]: ...
#     def __instancecheck__(self, instance: Any, /) -> bool: ...
#     def __subclasscheck__(self, subclass: type, /) -> bool: ...
#     @classmethod
#     def __prepare__(metacls, name: str, bases: tuple[type, ...], /, **kwds: Any) -> MutableMapping[str, object]: ...
#     # `int | str` produces an instance of `UnionType`, but `int | int` produces an instance of `type`,
#     # and `abc.ABC | abc.ABC` produces an instance of `abc.ABCMeta`.
#     def __or__(self: _typeshed.Self, value: Any, /) -> types.UnionType | _typeshed.Self: ...
#     def __ror__(self: _typeshed.Self, value: Any, /) -> types.UnionType | _typeshed.Self: ...
#     if sys.version_info >= (3, 12):
#         __type_params__: tuple[TypeVar | ParamSpec | TypeVarTuple, ...]
#     __annotations__: dict[str, AnnotationForm]
#     if sys.version_info >= (3, 14):
#         __annotate__: AnnotateFunc | None
# 
# @disjoint_base
# class super:
#     @overload
#     def __init__(self, t: Any, obj: Any, /) -> None: ...
#     @overload
#     def __init__(self, t: Any, /) -> None: ...
#     @overload
#     def __init__(self) -> None: ...

_PositiveInteger: TypeAlias = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]
_NegativeInteger: TypeAlias = Literal[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17, -18, -19, -20]
# _LiteralInteger = _PositiveInteger | _NegativeInteger | Literal[0]  # noqa: Y026  # TODO: Use TypeAlias once mypy bugs are fixed

# @disjoint_base
# class int:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions