From f5a536b505b971ca99ef878730f785a351f9b76f Mon Sep 17 00:00:00 2001 From: Jason Fried Date: Thu, 29 Oct 2020 13:40:55 -0700 Subject: [PATCH] ContextVar.get() default has wrong type, it should mirror Mapping.get (#4726) --- stdlib/3.7/contextvars.pyi | 8 ++++++-- tests/stubtest_whitelists/py37.txt | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/stdlib/3.7/contextvars.pyi b/stdlib/3.7/contextvars.pyi index 429d2037a..810b699b6 100644 --- a/stdlib/3.7/contextvars.pyi +++ b/stdlib/3.7/contextvars.pyi @@ -1,16 +1,20 @@ import sys -from typing import Any, Callable, ClassVar, Generic, Iterator, Mapping, TypeVar +from typing import Any, Callable, ClassVar, Generic, Iterator, Mapping, TypeVar, Union, overload if sys.version_info >= (3, 9): from types import GenericAlias _T = TypeVar("_T") +_D = TypeVar("_D") class ContextVar(Generic[_T]): def __init__(self, name: str, *, default: _T = ...) -> None: ... @property def name(self) -> str: ... - def get(self, default: _T = ...) -> _T: ... + @overload + def get(self) -> _T: ... + @overload + def get(self, default: Union[_D, _T]) -> Union[_D, _T]: ... def set(self, value: _T) -> Token[_T]: ... def reset(self, token: Token[_T]) -> None: ... if sys.version_info >= (3, 9): diff --git a/tests/stubtest_whitelists/py37.txt b/tests/stubtest_whitelists/py37.txt index b3070038b..8319eb0b5 100644 --- a/tests/stubtest_whitelists/py37.txt +++ b/tests/stubtest_whitelists/py37.txt @@ -23,6 +23,7 @@ collections.abc.AsyncGenerator.ag_frame collections.abc.AsyncGenerator.ag_running contextvars.Context.__init__ contextvars.Context.get +contextvars.ContextVar.get copy.PyStringMap ctypes.CDLL.__init__ dataclasses.Field.__init__