From c41f3e9bf946c5cb2fa53ed98380dc56977f82e8 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Sun, 20 Sep 2020 15:42:23 -0700 Subject: [PATCH] Define `NoneType` class in _typeshed Type checkers can use this to handle protocol matching for None (e.g. `foo: Hashable = None`). Co-authored-by: Eric Traut --- stdlib/2and3/_typeshed/__init__.pyi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stdlib/2and3/_typeshed/__init__.pyi b/stdlib/2and3/_typeshed/__init__.pyi index 04af18440..5efbc2517 100644 --- a/stdlib/2and3/_typeshed/__init__.pyi +++ b/stdlib/2and3/_typeshed/__init__.pyi @@ -16,7 +16,7 @@ import array import mmap import sys from typing import AbstractSet, Container, Iterable, Protocol, Text, Tuple, TypeVar, Union -from typing_extensions import Literal +from typing_extensions import Literal, final _KT = TypeVar("_KT") _KT_co = TypeVar("_KT_co", covariant=True) @@ -164,3 +164,8 @@ if sys.version_info >= (3,): else: ReadableBuffer = Union[bytes, bytearray, memoryview, array.array, mmap.mmap, buffer] WriteableBuffer = Union[bytearray, memoryview, array.array, mmap.mmap, buffer] + +# Used by type checkers for checks involving None (does not exist at runtime) +@final +class NoneType: + def __bool__(self) -> Literal[False]: ...