Skip to content
Myr

Type hinting: Low-hanging fruit improvements

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Clean out a series of ignores, either by specifying types or by reworking code slightly the ignore is no longer needed.

authored by Martijn Pieters · committed by David Lord · parent a1093bb · Browse files · 5 files+10 added−13 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+10 added−13 removed

  • other:+10 added−13 removed

5 files+10 added−13 removed

modified:src/click/_compat.py+1 added-1 removed
481 unmodified lines
482483 def __enter__(self) -> "_AtomicFile":484 return self485486 def __exit__(self, exc_type, exc_value, tb): # type: ignore486 def __exit__(self, exc_type: t.Optional[t.Type[BaseException]], *_: t.Any) -> None:487 self.close(delete=exc_type is not None)488489 def __repr__(self) -> str:490 return repr(self._f)
136 unmodified lines
modified:src/click/_termui_impl.py+1 added-1 removed
96 unmodified lines
97 self.entered = True98 self.render_progress()99 return self100101 def __exit__(self, exc_type, exc_value, tb): # type: ignore101 def __exit__(self, *_: t.Any) -> None:102 self.render_finish()103104 def __iter__(self) -> t.Iterator[V]:105 if not self.entered:
612 unmodified lines
modified:src/click/core.py+2 added-2 removed
453 unmodified lines
454 self._depth += 1455 push_context(self)456 return self457458 def __exit__(self, exc_type, exc_value, tb): # type: ignore458 def __exit__(self, *_: t.Any) -> None:459 self._depth -= 1460 if self._depth == 0:461 self.close()462 pop_context()
2353 unmodified lines
2816 # value as default.2817 if self.is_flag and not self.is_bool_flag:2818 for param in ctx.command.params:2819 if param.name == self.name and param.default:2820 return param.flag_value # type: ignore2820 return t.cast(Option, param).flag_value28212822 return None28232824 return super().get_default(ctx, call=call)
174 unmodified lines
modified:src/click/types.py+4 added-7 removed
700 unmodified lines
701702 lazy = self.resolve_lazy_flag(value)703704 if lazy:705 f: t.IO[t.Any] = t.cast(706 t.IO[t.Any],707 LazyFile(708 value, self.mode, self.encoding, self.errors, atomic=self.atomic705 lf = LazyFile(706 value, self.mode, self.encoding, self.errors, atomic=self.atomic709 ),707 )708709 if ctx is not None:713 ctx.call_on_close(f.close_intelligently) # type: ignore710 ctx.call_on_close(lf.close_intelligently)711715 return f712 return t.cast(t.IO[t.Any], lf)713714 f, should_close = open_stream(715 value, self.mode, self.encoding, self.errors, atomic=self.atomic716 )
354 unmodified lines
modified:src/click/utils.py+2 added-2 removed
172 unmodified lines
173174 def __enter__(self) -> "LazyFile":175 return self176177 def __exit__(self, exc_type, exc_value, tb): # type: ignore177 def __exit__(self, *_: t.Any) -> None:178 self.close_intelligently()179180 def __iter__(self) -> t.Iterator[t.AnyStr]:181 self.open()
9 unmodified lines
191192 def __enter__(self) -> "KeepOpenFile":193 return self194195 def __exit__(self, exc_type, exc_value, tb): # type: ignore195 def __exit__(self, *_: t.Any) -> None:196 pass197198 def __repr__(self) -> str:199 return repr(self._file)
383 unmodified lines