Skip to content

Add get_origin annotations #9811

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 17 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion stdlib/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ from types import (
)
from typing_extensions import Never as _Never, ParamSpec as _ParamSpec, final as _final

if sys.version_info >= (3, 10):
from types import UnionType
if sys.version_info >= (3, 9):
from types import GenericAlias

__all__ = [
"AbstractSet",
"Any",
Expand Down Expand Up @@ -745,9 +750,21 @@ else:
) -> dict[str, Any]: ...

if sys.version_info >= (3, 8):
def get_origin(tp: Any) -> Any | None: ...
def get_args(tp: Any) -> tuple[Any, ...]: ...

if sys.version_info >= (3, 10):
@overload
def get_origin(tp: ParamSpecArgs | ParamSpecKwargs) -> ParamSpec: ...
@overload
def get_origin(tp: UnionType) -> type[UnionType]: ...
if sys.version_info >= (3, 9):
@overload
def get_origin(tp: GenericAlias) -> type: ...
@overload
def get_origin(tp: Any) -> Any | None: ...
else:
def get_origin(tp: Any) -> Any | None: ...

@overload
def cast(typ: Type[_T], val: Any) -> _T: ...
@overload
Expand Down
17 changes: 17 additions & 0 deletions stdlib/typing_extensions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ from typing import ( # noqa: Y022,Y039
type_check_only,
)

if sys.version_info >= (3, 10):
from types import UnionType
if sys.version_info >= (3, 9):
from types import GenericAlias

__all__ = [
"Any",
"ClassVar",
Expand Down Expand Up @@ -155,6 +160,18 @@ def get_type_hints(
include_extras: bool = False,
) -> dict[str, Any]: ...
def get_args(tp: Any) -> tuple[Any, ...]: ...

if sys.version_info >= (3, 10):
@overload
def get_origin(tp: UnionType) -> type[UnionType]: ...

if sys.version_info >= (3, 9):
@overload
def get_origin(tp: GenericAlias) -> type: ...

@overload
def get_origin(tp: ParamSpecArgs | ParamSpecKwargs) -> ParamSpec: ...
@overload
def get_origin(tp: Any) -> Any | None: ...

Annotated: _SpecialForm
Expand Down