diff options
author | Martijn Pieters <mj@zopatista.com> | 2022-11-08 19:44:29 +0000 |
---|---|---|
committer | David Lord <davidism@gmail.com> | 2023-01-19 16:33:27 -0800 |
commit | a1093bbe0dae00eea8342247a0c2739b07a6acd8 (patch) | |
tree | 25c1680557687164f30ff08c5fa0e1e1693fac66 /src/click/utils.py | |
parent | a6c7ee060b02eaa62fd15264a669220914cfad4c (diff) | |
download | click-a1093bbe0dae00eea8342247a0c2739b07a6acd8.tar.gz |
Types: don't leave generic types without a parameter
Enable `disallow_any_generics` and provide type information for missing parameters for type hints.
Diffstat (limited to 'src/click/utils.py')
-rw-r--r-- | src/click/utils.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/click/utils.py b/src/click/utils.py index 8283788..fca3eba 100644 --- a/src/click/utils.py +++ b/src/click/utils.py @@ -120,7 +120,7 @@ class LazyFile: self.encoding = encoding self.errors = errors self.atomic = atomic - self._f: t.Optional[t.IO] + self._f: t.Optional[t.IO[t.Any]] if filename == "-": self._f, self.should_close = open_stream(filename, mode, encoding, errors) @@ -141,7 +141,7 @@ class LazyFile: return repr(self._f) return f"<unopened file '{self.name}' {self.mode}>" - def open(self) -> t.IO: + def open(self) -> t.IO[t.Any]: """Opens the file if it's not yet open. This call might fail with a :exc:`FileError`. Not handling this error will produce an error that Click shows. @@ -183,7 +183,7 @@ class LazyFile: class KeepOpenFile: - def __init__(self, file: t.IO) -> None: + def __init__(self, file: t.IO[t.Any]) -> None: self._file = file def __getattr__(self, name: str) -> t.Any: @@ -340,7 +340,7 @@ def open_file( errors: t.Optional[str] = "strict", lazy: bool = False, atomic: bool = False, -) -> t.IO: +) -> t.IO[t.Any]: """Open a file, with extra behavior to handle ``'-'`` to indicate a standard stream, lazy open on write, and atomic write. Similar to the behavior of the :class:`~click.File` param type. @@ -370,18 +370,20 @@ def open_file( .. versionadded:: 3.0 """ if lazy: - return t.cast(t.IO, LazyFile(filename, mode, encoding, errors, atomic=atomic)) + return t.cast( + t.IO[t.Any], LazyFile(filename, mode, encoding, errors, atomic=atomic) + ) f, should_close = open_stream(filename, mode, encoding, errors, atomic=atomic) if not should_close: - f = t.cast(t.IO, KeepOpenFile(f)) + f = t.cast(t.IO[t.Any], KeepOpenFile(f)) return f def format_filename( - filename: t.Union[str, bytes, os.PathLike], shorten: bool = False + filename: t.Union[str, bytes, "os.PathLike[t.AnyStr]"], shorten: bool = False ) -> str: """Formats a filename for user display. The main purpose of this function is to ensure that the filename can be displayed at all. This @@ -458,7 +460,7 @@ class PacifyFlushWrapper: pipe, all calls and attributes are proxied. """ - def __init__(self, wrapped: t.IO) -> None: + def __init__(self, wrapped: t.IO[t.Any]) -> None: self.wrapped = wrapped def flush(self) -> None: |