Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
21 changes: 20 additions & 1 deletion 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,7 +160,21 @@ def get_type_hints(
include_extras: bool = False,
) -> dict[str, Any]: ...
def get_args(tp: Any) -> tuple[Any, ...]: ...
def get_origin(tp: Any) -> Any | None: ...

if sys.version_info >= (3, 10):
@overload
def get_origin(tp: ParamSpecArgs | ParamSpecKwargs) -> ParamSpec: ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, actually, this overload can work on 3.7+ for typing_extensions (but not for typing, where ParamSpecs only exist on 3.10+):

(py37) C:\Users\alexw\coding\typeshed>python
Python 3.7.16 (default, Jan 17 2023, 16:06:28) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing_extensions import ParamSpec, get_origin
>>> type(get_origin(ParamSpec("P").args))
<class 'typing_extensions.ParamSpec'>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will take care of it later today. Thanks!

@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: ...

Annotated: _SpecialForm
_AnnotatedAlias: Any # undocumented
Expand Down