From 279ce7b01666a57e61e94514b39312c02a3184d2 Mon Sep 17 00:00:00 2001 From: jorenham Date: Tue, 12 May 2026 22:07:16 +0200 Subject: [PATCH 1/2] Add type annotations for instance attributes in `utils` --- src/click/utils.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/click/utils.py b/src/click/utils.py index e2e3fe5f12..a987437acc 100644 --- a/src/click/utils.py +++ b/src/click/utils.py @@ -117,6 +117,14 @@ class LazyFile: files for writing. """ + name: str + mode: str + encoding: str | None + errors: str | None + atomic: bool + _f: t.IO[t.Any] | None + should_close: bool + def __init__( self, filename: str | os.PathLike[str], @@ -124,14 +132,12 @@ def __init__( encoding: str | None = None, errors: str | None = "strict", atomic: bool = False, - ): - self.name: str = os.fspath(filename) + ) -> None: + self.name = os.fspath(filename) self.mode = mode self.encoding = encoding self.errors = errors self.atomic = atomic - self._f: t.IO[t.Any] | None - self.should_close: bool if self.name == "-": self._f, self.should_close = open_stream(filename, mode, encoding, errors) @@ -508,6 +514,8 @@ class PacifyFlushWrapper: pipe, all calls and attributes are proxied. """ + wrapped: t.IO[t.Any] + def __init__(self, wrapped: t.IO[t.Any]) -> None: self.wrapped = wrapped From fc41aa1d0b62494eb93e92ff3929601221e3abf4 Mon Sep 17 00:00:00 2001 From: Kevin Deldycke Date: Sat, 16 May 2026 07:46:07 +0200 Subject: [PATCH 2/2] Apply class-body annotations to `KeepOpenFile` for consistency --- src/click/utils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/click/utils.py b/src/click/utils.py index a987437acc..223d6b8d7b 100644 --- a/src/click/utils.py +++ b/src/click/utils.py @@ -205,8 +205,10 @@ def __iter__(self) -> cabc.Iterator[t.AnyStr]: class KeepOpenFile: + _file: t.IO[t.Any] + def __init__(self, file: t.IO[t.Any]) -> None: - self._file: t.IO[t.Any] = file + self._file = file def __getattr__(self, name: str) -> t.Any: return getattr(self._file, name)