From 646993c2110fc7c5bcb10b3b0c533f0c3f4ac644 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Fri, 1 Apr 2022 18:01:23 +0100 Subject: [PATCH] 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: ...` --- stdlib/imp.pyi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stdlib/imp.pyi b/stdlib/imp.pyi index ec09d18de..3054a4465 100644 --- a/stdlib/imp.pyi +++ b/stdlib/imp.pyi @@ -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: ...