Improve mmap.mmap.__enter__ (#7461)

It returns `Self` at runtime, not `mmap.mmap`, so inheriting from `AbstractContextManager` doesn't really do anything for us.
This commit is contained in:
Alex Waygood
2022-03-08 15:47:56 +00:00
committed by GitHub
parent 70988f1811
commit db6f912c77

View File

@@ -1,6 +1,5 @@
import sys
from _typeshed import ReadableBuffer
from contextlib import AbstractContextManager
from _typeshed import ReadableBuffer, Self
from typing import Iterable, Iterator, NoReturn, Sized, overload
ACCESS_DEFAULT: int
@@ -27,7 +26,7 @@ if sys.platform != "win32":
PAGESIZE: int
class mmap(AbstractContextManager[mmap], Iterable[int], Sized):
class mmap(Iterable[int], Sized):
if sys.platform == "win32":
def __init__(self, fileno: int, length: int, tagname: str | None = ..., access: int = ..., offset: int = ...) -> None: ...
else:
@@ -70,6 +69,7 @@ class mmap(AbstractContextManager[mmap], Iterable[int], Sized):
# Doesn't actually exist, but the object is actually iterable because it has __getitem__ and
# __len__, so we claim that there is also an __iter__ to help type checkers.
def __iter__(self) -> Iterator[int]: ...
def __enter__(self: Self) -> Self: ...
def __exit__(self, *args: object) -> None: ...
if sys.version_info >= (3, 8) and sys.platform != "win32":