summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartijn Pieters <mj@zopatista.com>2022-11-09 17:03:49 +0000
committerDavid Lord <davidism@gmail.com>2023-01-19 16:33:27 -0800
commit085f414a046bd5f15dfa08bedd0aa50f25410520 (patch)
tree5340cf1aea7c3bf068f1fc9fc2db7a2650b86fe8
parenta1093bbe0dae00eea8342247a0c2739b07a6acd8 (diff)
downloadclick-085f414a046bd5f15dfa08bedd0aa50f25410520.tar.gz
Type hinting: Low-hanging fruit improvements
Clean out a series of ignores, either by specifying types or by reworking code slightly the ignore is no longer needed.
-rw-r--r--src/click/_compat.py2
-rw-r--r--src/click/_termui_impl.py2
-rw-r--r--src/click/core.py4
-rw-r--r--src/click/types.py11
-rw-r--r--src/click/utils.py4
5 files changed, 10 insertions, 13 deletions
diff --git a/src/click/_compat.py b/src/click/_compat.py
index 57faa91..e55a713 100644
--- a/src/click/_compat.py
+++ b/src/click/_compat.py
@@ -483,7 +483,7 @@ class _AtomicFile:
def __enter__(self) -> "_AtomicFile":
return self
- def __exit__(self, exc_type, exc_value, tb): # type: ignore
+ def __exit__(self, exc_type: t.Optional[t.Type[BaseException]], *_: t.Any) -> None:
self.close(delete=exc_type is not None)
def __repr__(self) -> str:
diff --git a/src/click/_termui_impl.py b/src/click/_termui_impl.py
index 1caaad8..a050471 100644
--- a/src/click/_termui_impl.py
+++ b/src/click/_termui_impl.py
@@ -98,7 +98,7 @@ class ProgressBar(t.Generic[V]):
self.render_progress()
return self
- def __exit__(self, exc_type, exc_value, tb): # type: ignore
+ def __exit__(self, *_: t.Any) -> None:
self.render_finish()
def __iter__(self) -> t.Iterator[V]:
diff --git a/src/click/core.py b/src/click/core.py
index 9aef380..1a85bab 100644
--- a/src/click/core.py
+++ b/src/click/core.py
@@ -455,7 +455,7 @@ class Context:
push_context(self)
return self
- def __exit__(self, exc_type, exc_value, tb): # type: ignore
+ def __exit__(self, *_: t.Any) -> None:
self._depth -= 1
if self._depth == 0:
self.close()
@@ -2817,7 +2817,7 @@ class Option(Parameter):
if self.is_flag and not self.is_bool_flag:
for param in ctx.command.params:
if param.name == self.name and param.default:
- return param.flag_value # type: ignore
+ return t.cast(Option, param).flag_value
return None
diff --git a/src/click/types.py b/src/click/types.py
index 1b04e37..57866ec 100644
--- a/src/click/types.py
+++ b/src/click/types.py
@@ -702,17 +702,14 @@ class File(ParamType):
lazy = self.resolve_lazy_flag(value)
if lazy:
- f: t.IO[t.Any] = t.cast(
- t.IO[t.Any],
- LazyFile(
- value, self.mode, self.encoding, self.errors, atomic=self.atomic
- ),
+ lf = LazyFile(
+ value, self.mode, self.encoding, self.errors, atomic=self.atomic
)
if ctx is not None:
- ctx.call_on_close(f.close_intelligently) # type: ignore
+ ctx.call_on_close(lf.close_intelligently)
- return f
+ return t.cast(t.IO[t.Any], lf)
f, should_close = open_stream(
value, self.mode, self.encoding, self.errors, atomic=self.atomic
diff --git a/src/click/utils.py b/src/click/utils.py
index fca3eba..8f3fb57 100644
--- a/src/click/utils.py
+++ b/src/click/utils.py
@@ -174,7 +174,7 @@ class LazyFile:
def __enter__(self) -> "LazyFile":
return self
- def __exit__(self, exc_type, exc_value, tb): # type: ignore
+ def __exit__(self, *_: t.Any) -> None:
self.close_intelligently()
def __iter__(self) -> t.Iterator[t.AnyStr]:
@@ -192,7 +192,7 @@ class KeepOpenFile:
def __enter__(self) -> "KeepOpenFile":
return self
- def __exit__(self, exc_type, exc_value, tb): # type: ignore
+ def __exit__(self, *_: t.Any) -> None:
pass
def __repr__(self) -> str: