Improve imp._FileLike.__exit__ (#7577)

The signature of this method currently doesn't work quite as intended: see https://github.com/PyCQA/flake8-pyi/pull/199#issuecomment-1086087342

Classes will [still be accepted](https://mypy-play.net/?mypy=latest&python=3.10&gist=77efe095d01edeb1a4614166f0c9cf68) as conforming to this protocol if they have more permissive signatures such as `def __exit__(self, *args: object) -> None: ...`
This commit is contained in:
Alex Waygood
2022-04-01 18:01:23 +01:00
committed by GitHub
parent ec27c00ca2
commit 646993c211

View File

@@ -1,6 +1,7 @@
import types
from _typeshed import StrPath
from os import PathLike
from types import TracebackType
from typing import IO, Any, Protocol
from _imp import (
@@ -45,7 +46,7 @@ class _FileLike(Protocol):
def read(self) -> str | bytes: ...
def close(self) -> Any: ...
def __enter__(self) -> Any: ...
def __exit__(self, *args: Any) -> Any: ...
def __exit__(self, typ: type[BaseException] | None, exc: BaseException | None, tb: TracebackType | None) -> Any: ...
# PathLike doesn't work for the pathname argument here
def load_source(name: str, pathname: str, file: _FileLike | None = ...) -> types.ModuleType: ...