Repository navigation
Copy typechecker-internal symbols to _typeshed._type_checker_internals
#13816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f97f62e
Copy typechecker-internal symbols to `_typeshed._tc`
srittau 44554bb
Linter fixes
srittau 6d65b3b
Remove `function` in favor of `types.FunctionType`
srittau 053e4d1
Rename `_promote` to `promote`
srittau a5c690b
Rename `_TypedDict` to `TypedDictFallback`
srittau dd0825c
Add NamedTupleFallback
srittau fd702ba
Update comments to not refer to mypy exclusively
srittau 1820b33
_tc -> _tc_internals
srittau f57d9f5
Rename to _type_checker_internals
srittau a9edca4
Merge branch 'main' into type-checker-internals
srittau a5c4219
Merge branch 'main' into type-checker-internals
srittau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| # Internals used by some type checkers. | ||
| # | ||
| # Don't use this module directly. It is only for type checkers to use. | ||
|
|
||
| import sys | ||
| import typing_extensions | ||
| from _collections_abc import dict_items, dict_keys, dict_values | ||
| from abc import ABCMeta | ||
| from collections.abc import Awaitable, Generator, Iterable, Mapping | ||
| from typing import Any, ClassVar, Generic, TypeVar, overload | ||
| from typing_extensions import Never | ||
|
|
||
| _T = TypeVar("_T") | ||
|
|
||
| # Used for an undocumented mypy feature. Does not exist at runtime. | ||
| promote = object() | ||
|
|
||
| # Internal mypy fallback type for all typed dicts. | ||
| # N.B. Keep this mostly in sync with typing_extensions._TypedDict/mypy_extensions._TypedDict | ||
| class TypedDictFallback(Mapping[str, object], metaclass=ABCMeta): | ||
| __total__: ClassVar[bool] | ||
| __required_keys__: ClassVar[frozenset[str]] | ||
| __optional_keys__: ClassVar[frozenset[str]] | ||
| # __orig_bases__ sometimes exists on <3.12, but not consistently, | ||
| # so we only add it to the stub on 3.12+ | ||
| if sys.version_info >= (3, 12): | ||
| __orig_bases__: ClassVar[tuple[Any, ...]] | ||
| if sys.version_info >= (3, 13): | ||
| __readonly_keys__: ClassVar[frozenset[str]] | ||
| __mutable_keys__: ClassVar[frozenset[str]] | ||
|
|
||
| def copy(self) -> typing_extensions.Self: ... | ||
| # Using Never so that only calls using mypy plugin hook that specialize the signature | ||
| # can go through. | ||
| def setdefault(self, k: Never, default: object) -> object: ... | ||
| # Mypy plugin hook for 'pop' expects that 'default' has a type variable type. | ||
| def pop(self, k: Never, default: _T = ...) -> object: ... # pyright: ignore[reportInvalidTypeVarUse] | ||
| def update(self, m: typing_extensions.Self, /) -> None: ... | ||
| def __delitem__(self, k: Never) -> None: ... | ||
| def items(self) -> dict_items[str, object]: ... | ||
| def keys(self) -> dict_keys[str, object]: ... | ||
| def values(self) -> dict_values[str, object]: ... | ||
| @overload | ||
| def __or__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ... | ||
| @overload | ||
| def __or__(self, value: dict[str, Any], /) -> dict[str, object]: ... | ||
| @overload | ||
| def __ror__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ... | ||
| @overload | ||
| def __ror__(self, value: dict[str, Any], /) -> dict[str, object]: ... | ||
| # supposedly incompatible definitions of __or__ and __ior__ | ||
| def __ior__(self, value: typing_extensions.Self, /) -> typing_extensions.Self: ... # type: ignore[misc] | ||
|
|
||
| class NamedTupleFallback(tuple[Any, ...]): | ||
|
srittau marked this conversation as resolved.
Resolved
|
||
| _field_defaults: ClassVar[dict[str, Any]] | ||
| _fields: ClassVar[tuple[str, ...]] | ||
| # __orig_bases__ sometimes exists on <3.12, but not consistently | ||
| # So we only add it to the stub on 3.12+. | ||
| if sys.version_info >= (3, 12): | ||
| __orig_bases__: ClassVar[tuple[Any, ...]] | ||
|
|
||
| @overload | ||
| def __init__(self, typename: str, fields: Iterable[tuple[str, Any]], /) -> None: ... | ||
| @overload | ||
| @typing_extensions.deprecated( | ||
| "Creating a typing.NamedTuple using keyword arguments is deprecated and support will be removed in Python 3.15" | ||
| ) | ||
| def __init__(self, typename: str, fields: None = None, /, **kwargs: Any) -> None: ... | ||
| @classmethod | ||
| def _make(cls, iterable: Iterable[Any]) -> typing_extensions.Self: ... | ||
| def _asdict(self) -> dict[str, Any]: ... | ||
| def _replace(self, **kwargs: Any) -> typing_extensions.Self: ... | ||
| if sys.version_info >= (3, 13): | ||
| def __replace__(self, **kwargs: Any) -> typing_extensions.Self: ... | ||
|
|
||
| # Non-default variations to accommodate couroutines, and `AwaitableGenerator` having a 4th type parameter. | ||
| _S = TypeVar("_S") | ||
| _YieldT_co = TypeVar("_YieldT_co", covariant=True) | ||
| _SendT_nd_contra = TypeVar("_SendT_nd_contra", contravariant=True) | ||
| _ReturnT_nd_co = TypeVar("_ReturnT_nd_co", covariant=True) | ||
|
|
||
| # The parameters correspond to Generator, but the 4th is the original type. | ||
| class AwaitableGenerator( | ||
| Awaitable[_ReturnT_nd_co], | ||
| Generator[_YieldT_co, _SendT_nd_contra, _ReturnT_nd_co], | ||
| Generic[_YieldT_co, _SendT_nd_contra, _ReturnT_nd_co, _S], | ||
| metaclass=ABCMeta, | ||
| ): ... | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.