constructors: Fix defaulted TypeVars (#7965)

From the list in https://github.com/microsoft/pyright/issues/3501
This commit is contained in:
Jelle Zijlstra
2022-05-26 23:32:56 -07:00
committed by GitHub
parent 62a8a6922c
commit 789c12ad90
5 changed files with 23 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
import sys
from _typeshed import Self
from collections.abc import Iterable, Iterator, MutableSet
from typing import Any, Generic, TypeVar
from typing import Any, Generic, TypeVar, overload
if sys.version_info >= (3, 9):
from types import GenericAlias
@@ -12,7 +12,10 @@ _S = TypeVar("_S")
_T = TypeVar("_T")
class WeakSet(MutableSet[_T], Generic[_T]):
def __init__(self, data: Iterable[_T] | None = ...) -> None: ...
@overload
def __init__(self, data: None = ...) -> None: ...
@overload
def __init__(self, data: Iterable[_T]) -> None: ...
def add(self, item: _T) -> None: ...
def clear(self) -> None: ...
def discard(self, item: _T) -> None: ...

View File

@@ -14,7 +14,10 @@ _P = ParamSpec("_P")
@final
class ContextVar(Generic[_T]):
def __init__(self, name: str, *, default: _T = ...) -> None: ...
@overload
def __init__(self, name: str) -> None: ...
@overload
def __init__(self, name: str, *, default: _T) -> None: ...
@property
def name(self) -> str: ...
@overload

View File

@@ -1,7 +1,7 @@
import sys
from _typeshed import SupportsItems
from collections.abc import Iterable
from typing import Any, Generic, TypeVar
from typing import Any, Generic, TypeVar, overload
__all__ = ["TopologicalSorter", "CycleError"]
@@ -11,7 +11,10 @@ if sys.version_info >= (3, 11):
from types import GenericAlias
class TopologicalSorter(Generic[_T]):
def __init__(self, graph: SupportsItems[_T, Iterable[_T]] | None = ...) -> None: ...
@overload
def __init__(self, graph: None = ...) -> None: ...
@overload
def __init__(self, graph: SupportsItems[_T, Iterable[_T]]) -> None: ...
def add(self, node: _T, *predecessors: _T) -> None: ...
def prepare(self) -> None: ...
def is_active(self) -> bool: ...