use ruff lint and format
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 93b7ab5 · Browse files · 18 files·+54 added−90 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
18 files+54 added−90 removed
- tests:+4 added−6 removed
- other:+50 added−84 removed
Provenance
- Commit
9cf4e64- Tree
cbc258d- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
93b7ab5
18 files changed+54 added−90 removed
modified:src/click/_compat.py+1 added-3 removed
517 unmodified lines518 return locale.getpreferredencoding()519 520 _ansi_stream_wrappers: cabc.MutableMapping[t.TextIO, t.TextIO] = WeakKeyDictionary()521 522- def auto_wrap_for_ansi( # noqa: F811523- stream: t.TextIO, color: bool | None = None524- ) -> t.TextIO:522+ def auto_wrap_for_ansi(stream: t.TextIO, color: bool | None = None) -> t.TextIO:523 """Support ANSI color and style codes on Windows by wrapping a524 stream with colorama.525 """526 try:96 unmodified linesmodified:src/click/_termui_impl.py+1 added-1 removed
697 unmodified lines698 _translate_ch_to_exc(rv)699 return rv700 701 else:702- import tty702 import termios703+ import tty704 705 @contextlib.contextmanager706 def raw_terminal() -> cabc.Iterator[int]:707 f: t.TextIO | None33 unmodified linesmodified:src/click/_winconsole.py+1 added-1 removed
74 unmodified lines75 get_buffer = None76 else:77 78 class Py_buffer(Structure):79- _fields_ = [79+ _fields_ = [ # noqa: RUF01280 ("buf", c_void_p),81 ("obj", py_object),82 ("len", c_ssize_t),83 ("itemsize", c_ssize_t),199 unmodified linesmodified:src/click/core.py+4 added-17 removed
722 unmodified lines723 return type(self)(command, info_name=command.name, parent=self)724 725 @t.overload726 def invoke(727- __self, # noqa: B902728- __callback: t.Callable[..., V],729- *args: t.Any,730- **kwargs: t.Any,727+ __self, __callback: t.Callable[..., V], *args: t.Any, **kwargs: t.Any728 ) -> V:729 ...730 731 @t.overload735- def invoke(736- __self, # noqa: B902737- __callback: Command,738- *args: t.Any,739- **kwargs: t.Any,740- ) -> t.Any:732+ def invoke(__self, __callback: Command, *args: t.Any, **kwargs: t.Any) -> t.Any:733 ...734 735 def invoke(744- __self, # noqa: B902745- __callback: Command | t.Callable[..., V],746- *args: t.Any,747- **kwargs: t.Any,736+ __self, __callback: Command | t.Callable[..., V], *args: t.Any, **kwargs: t.Any737 ) -> t.Any | V:738 """Invokes a command callback in exactly the way it expects. There739 are two ways to invoke this method:740 38 unmodified lines779 with augment_usage_errors(__self):780 with ctx:781 return __callback(*args, **kwargs)782 794- def forward(795- __self, __cmd: Command, *args: t.Any, **kwargs: t.Any # noqa: B902796- ) -> t.Any:783+ def forward(__self, __cmd: Command, *args: t.Any, **kwargs: t.Any) -> t.Any:784 """Similar to :meth:`invoke` but fills in default keyword785 arguments from the current context if the other command expects786 it. This cannot invoke callbacks directly, only other commands.787 2197 unmodified linesmodified:src/click/parser.py+3 added-1 removed
509 unmodified lines510 "ParsingState",511 }:512 warnings.warn(513 f"'parser.{name}' is deprecated and will be removed in Click 9.0."514- " The old parser is available in 'optparse'."514+ " The old parser is available in 'optparse'.",515+ DeprecationWarning,516+ stacklevel=2,517 )518 return globals()[f"_{name}"]519 520 if name == "split_arg_string":11 unmodified linesmodified:src/click/termui.py+1 added-1 removed
175 unmodified lines176 except UsageError as e:177 if hide_input:178 echo(_("Error: The value you entered was invalid."), err=err)179 else:180- echo(_("Error: {e.message}").format(e=e), err=err) # noqa: B306180+ echo(_("Error: {e.message}").format(e=e), err=err)181 continue182 if not confirmation_prompt:183 return result184 while True:602 unmodified linesmodified:src/click/testing.py+1 added-1 removed
475 unmodified lines476 477 if temp_dir is None:478 try:479 shutil.rmtree(dt)480- except OSError: # noqa: B014480+ except OSError:481 passmodified:src/click/types.py+2 added-1 removed
16 unmodified lines17 from .utils import safecall18 19 if t.TYPE_CHECKING:20 import typing_extensions as te21+22 from .core import Context23 from .core import Parameter24 from .shell_completion import CompletionItem25 716 unmodified lines742 else:743 ctx.call_on_close(safecall(f.flush))744 745 return f745- except OSError as e: # noqa: B014746+ except OSError as e:747 self.fail(f"'{format_filename(value)}': {e.strerror}", param, ctx)748 749 def shell_complete(750 self, ctx: Context, param: Parameter, incomplete: str341 unmodified linesmodified:src/click/utils.py+1 added-1 removed
157 unmodified lines158 try:159 rv, self.should_close = open_stream(160 self.name, self.mode, self.encoding, self.errors, atomic=self.atomic161 )162- except OSError as e: # noqa: E402162+ except OSError as e:163 from .exceptions import FileError164 165 raise FileError(self.name, hint=e.strerror) from e166 self._f = rv461 unmodified linesmodified:tests/test_defaults.py+2 added-2 removed
3 unmodified lines4 def test_basic_defaults(runner):5 @click.command()6 @click.option("--foo", default=42, type=click.FLOAT)7 def cli(foo):8- assert type(foo) is float8+ assert isinstance(foo, float)9 click.echo(f"FOO:[{foo}]")10 11 result = runner.invoke(cli, [])12 assert not result.exception4 unmodified lines17 @click.command()18 @click.option("--foo", default=[23, 42], type=click.FLOAT, multiple=True)19 def cli(foo):20 for item in foo:21- assert type(item) is float21+ assert isinstance(item, float)22 click.echo(item)23 24 result = runner.invoke(cli, [])25 assert not result.exception36 unmodified linesmodified:tests/test_imports.py-1 removed
2 unmodified lines3 import sys4 5 from click._compat import WIN6 7-7 IMPORT_TEST = b"""\8 import builtins9 10 found_imports = set()59 unmodified linesmodified:tests/test_normalization.py-1 removed
1 import click2 3-3 CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())4 5 6 def test_option_normalization(runner):32 unmodified linesmodified:tests/test_testing.py+1 added-1 removed
319 unmodified lines320 assert result_mix.output == "stdout\nstderr\n"321 assert result_mix.stdout == "stdout\nstderr\n"322 323 with pytest.raises(ValueError):324- result_mix.stderr324+ assert result_mix.stderr325 326 @click.command()327 def cli_empty_stderr():328 click.echo("stdout")92 unmodified linesmodified:tests/test_utils.py+1 added-1 removed
239 unmodified lines240 def test_prompt_cast_default(capfd, monkeypatch):241 monkeypatch.setattr(sys, "stdin", StringIO("\n"))242 value = click.prompt("value", default="100", type=int)243 capfd.readouterr()244- assert type(value) is int244+ assert isinstance(value, int)245 246 247 @pytest.mark.skipif(WIN, reason="Test too complex to make work windows.")248 def test_echo_writing_to_standard_error(capfd, monkeypatch):259 unmodified linesdeleted:.flake8-25 removed
1-[flake8]2-extend-select =3- # bugbear4- B5- # bugbear opinions6- B97- # implicit str concat8- ISC9-extend-ignore =10- # slice notation whitespace, invalid11- E20312- # line length, handled by bugbear B95013- E50114- # bare except, handled by bugbear B00115- E72216- # zip with strict=, requires python >= 3.1017- B90518- # string formatting opinion, B028 renamed to B90719- B02820- B90721-# up to 88 allowed by bugbear B95022-max-line-length = 8023-per-file-ignores =24- # __init__ exports names25- src/click/__init__.py: F401modified:.gitignore+5 added-10 removed
1 /.idea/2 /.vscode/3-.DS_Store/4-/env/5-/venv/3 __pycache__/7-*.pyc8-*.egg-info/9-/build/10-/dist/11-/.pytest_cache/4 /.tox/13-.coverage14-.coverage.*5+/.coverage6+/.coverage.*7 /htmlcov/8 /docs/_build/9+/dist/10+/venv*/11+/.venv*/modified:.pre-commit-config.yaml+7 added-22 removed
1 ci:2- autoupdate_branch: "8.1.x"2 autoupdate_schedule: monthly3 repos:5- - repo: https://github.com/asottile/pyupgrade6- rev: v3.10.14+ - repo: https://github.com/astral-sh/ruff-pre-commit5+ rev: v0.1.96 hooks:8- - id: pyupgrade9- args: ["--py38-plus"]10- - repo: https://github.com/asottile/reorder-python-imports11- rev: v3.10.012- hooks:13- - id: reorder-python-imports14- args: ["--application-directories", "src"]15- - repo: https://github.com/psf/black16- rev: 23.7.017- hooks:18- - id: black19- - repo: https://github.com/PyCQA/flake820- rev: 6.1.021- hooks:22- - id: flake823- additional_dependencies:24- - flake8-bugbear25- - flake8-implicit-str-concat7+ - id: ruff8+ - id: ruff-format9 - repo: https://github.com/pre-commit/pre-commit-hooks27- rev: v4.4.010+ rev: v4.5.011 hooks:12+ - id: check-merge-conflict13+ - id: debug-statements14 - id: fix-byte-order-marker15 - id: trailing-whitespace16 - id: end-of-file-fixermodified:pyproject.toml+23 added
68 unmodified lines69 module = [70 "colorama.*",71 ]72 ignore_missing_imports = true73+74+[tool.ruff]75+extend-exclude = ["examples/"]76+src = ["src"]77+fix = true78+show-fixes = true79+show-source = true80+81+[tool.ruff.lint]82+select = [83+ "B", # flake8-bugbear84+ "E", # pycodestyle error85+ "F", # pyflakes86+ "I", # isort87+ "RUF", # ruff-specific rules88+ "UP", # pyupgrade89+ "W", # pycodestyle warning90+]91+ignore-init-module-imports = true92+93+[tool.ruff.lint.isort]94+force-single-line = true95+order-by-type = false