[contextlib] adjust nullcontext.__init__ to fix divergences in type checkers (#15482)

This commit is contained in:
pinterior
2026-03-04 17:33:00 +09:00
committed by GitHub
parent 7c9d622f5b
commit b0401bc7df
+2 -2
View File
@@ -210,7 +210,7 @@ if sys.version_info >= (3, 10):
class nullcontext(AbstractContextManager[_T, None], AbstractAsyncContextManager[_T, None]):
enter_result: _T
@overload
def __init__(self: nullcontext[None], enter_result: None = None) -> None: ...
def __init__(self: nullcontext[None]) -> None: ...
@overload
def __init__(self: nullcontext[_T], enter_result: _T) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] #11780
def __enter__(self) -> _T: ...
@@ -222,7 +222,7 @@ else:
class nullcontext(AbstractContextManager[_T, None]):
enter_result: _T
@overload
def __init__(self: nullcontext[None], enter_result: None = None) -> None: ...
def __init__(self: nullcontext[None]) -> None: ...
@overload
def __init__(self: nullcontext[_T], enter_result: _T) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] #11780
def __enter__(self) -> _T: ...