-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix new style union syntax in type aliases (#14008)
Fix Python 3.10 `|` union syntax in type aliases, when one of the operands is a type alias or a type with an overloaded `__init__`. We can now infer `typing._SpecialForm` for type aliases in a runtime context. Also create a bunch of minimal test-only stubs for stdlib modules to fix some test failures caused by the missing `typing._SpecialForm` in the default test stubs. This is generally what we want in any case, since using typeshed stubs with minimal builtins/typing stubs can result in unpredictable behavior and slow tests. Fixes #12368. Fixes #12005. Fixes #11426.
- Loading branch information
Showing
21 changed files
with
186 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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,4 @@ | ||
# Very simplified decimal stubs for use in tests | ||
|
||
class Decimal: | ||
def __new__(cls, value: str = ...) -> Decimal: ... |
This file contains 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,16 @@ | ||
# Very simplified datetime stubs for use in tests | ||
|
||
class datetime: | ||
def __new__( | ||
cls, | ||
year: int, | ||
month: int, | ||
day: int, | ||
hour: int = ..., | ||
minute: int = ..., | ||
second: int = ..., | ||
microsecond: int = ..., | ||
*, | ||
fold: int = ..., | ||
) -> datetime: ... | ||
def __format__(self, __fmt: str) -> str: ... |
This file contains 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,3 @@ | ||
# Very simplified decimal stubs for use in tests | ||
|
||
from _decimal import * |
This file contains 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,35 @@ | ||
from typing import Generic, TypeVar, Callable, Any, Mapping | ||
|
||
_T = TypeVar("_T") | ||
|
||
class _SingleDispatchCallable(Generic[_T]): | ||
registry: Mapping[Any, Callable[..., _T]] | ||
def dispatch(self, cls: Any) -> Callable[..., _T]: ... | ||
# @fun.register(complex) | ||
# def _(arg, verbose=False): ... | ||
@overload | ||
def register(self, cls: type[Any], func: None = ...) -> Callable[[Callable[..., _T]], Callable[..., _T]]: ... | ||
# @fun.register | ||
# def _(arg: int, verbose=False): | ||
@overload | ||
def register(self, cls: Callable[..., _T], func: None = ...) -> Callable[..., _T]: ... | ||
# fun.register(int, lambda x: x) | ||
@overload | ||
def register(self, cls: type[Any], func: Callable[..., _T]) -> Callable[..., _T]: ... | ||
def _clear_cache(self) -> None: ... | ||
def __call__(__self, *args: Any, **kwargs: Any) -> _T: ... | ||
|
||
def singledispatch(func: Callable[..., _T]) -> _SingleDispatchCallable[_T]: ... | ||
|
||
def total_ordering(cls: type[_T]) -> type[_T]: ... | ||
|
||
class cached_property(Generic[_T]): | ||
func: Callable[[Any], _T] | ||
attrname: str | None | ||
def __init__(self, func: Callable[[Any], _T]) -> None: ... | ||
@overload | ||
def __get__(self, instance: None, owner: type[Any] | None = ...) -> cached_property[_T]: ... | ||
@overload | ||
def __get__(self, instance: object, owner: type[Any] | None = ...) -> _T: ... | ||
def __set_name__(self, owner: type[Any], name: str) -> None: ... | ||
def __class_getitem__(cls, item: Any) -> Any: ... |
This file contains 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,3 @@ | ||
# Very simplified traceback stubs for use in tests | ||
|
||
def print_tb(*args, **kwargs) -> None: ... |
Oops, something went wrong.