Skip to content
Myr

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

18 files+54 added−90 removed

modified:src/click/_compat.py+1 added-3 removed
517 unmodified lines
518 return locale.getpreferredencoding()519520 _ansi_stream_wrappers: cabc.MutableMapping[t.TextIO, t.TextIO] = WeakKeyDictionary()521522 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 lines
modified:src/click/_termui_impl.py+1 added-1 removed
697 unmodified lines
698 _translate_ch_to_exc(rv)699 return rv700701else:702 import tty702 import termios703 import tty704705 @contextlib.contextmanager706 def raw_terminal() -> cabc.Iterator[int]:707 f: t.TextIO | None
33 unmodified lines
modified:src/click/_winconsole.py+1 added-1 removed
74 unmodified lines
75 get_buffer = None76else:7778 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 lines
modified:src/click/core.py+4 added-17 removed
722 unmodified lines
723 return type(self)(command, info_name=command.name, parent=self)724725 @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 ...730731 @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 ...734735 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 lines
779 with augment_usage_errors(__self):780 with ctx:781 return __callback(*args, **kwargs)782794 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 lines
modified:src/click/parser.py+3 added-1 removed
509 unmodified lines
510 "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}"]519520 if name == "split_arg_string":
11 unmodified lines
modified:src/click/termui.py+1 added-1 removed
175 unmodified lines
176 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 lines
modified:src/click/testing.py+1 added-1 removed
475 unmodified lines
476477 if temp_dir is None:478 try:479 shutil.rmtree(dt)480 except OSError: # noqa: B014480 except OSError:481 pass
modified:src/click/types.py+2 added-1 removed
16 unmodified lines
17from .utils import safecall1819if t.TYPE_CHECKING:20 import typing_extensions as te2122 from .core import Context23 from .core import Parameter24 from .shell_completion import CompletionItem25
716 unmodified lines
742 else:743 ctx.call_on_close(safecall(f.flush))744745 return f745 except OSError as e: # noqa: B014746 except OSError as e:747 self.fail(f"'{format_filename(value)}': {e.strerror}", param, ctx)748749 def shell_complete(750 self, ctx: Context, param: Parameter, incomplete: str
341 unmodified lines
modified:src/click/utils.py+1 added-1 removed
157 unmodified lines
158 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 FileError164165 raise FileError(self.name, hint=e.strerror) from e166 self._f = rv
461 unmodified lines
modified:tests/test_defaults.py+2 added-2 removed
3 unmodified lines
4def 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}]")1011 result = runner.invoke(cli, [])12 assert not result.exception
4 unmodified lines
17 @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)2324 result = runner.invoke(cli, [])25 assert not result.exception
36 unmodified lines
modified:tests/test_imports.py-1 removed
2 unmodified lines
3import sys45from click._compat import WIN677IMPORT_TEST = b"""\8import builtins910found_imports = set()
59 unmodified lines
modified:tests/test_normalization.py-1 removed
1import click233CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())456def test_option_normalization(runner):
32 unmodified lines
modified:tests/test_testing.py+1 added-1 removed
319 unmodified lines
320 assert result_mix.output == "stdout\nstderr\n"321 assert result_mix.stdout == "stdout\nstderr\n"322323 with pytest.raises(ValueError):324 result_mix.stderr324 assert result_mix.stderr325326 @click.command()327 def cli_empty_stderr():328 click.echo("stdout")
92 unmodified lines
modified:tests/test_utils.py+1 added-1 removed
239 unmodified lines
240def 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)245246247@pytest.mark.skipif(WIN, reason="Test too complex to make work windows.")248def test_echo_writing_to_standard_error(capfd, monkeypatch):
259 unmodified lines
deleted:.flake8-25 removed
1[flake8]2extend-select =3 # bugbear4 B5 # bugbear opinions6 B97 # implicit str concat8 ISC9extend-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 B95022max-line-length = 8023per-file-ignores =24 # __init__ exports names25 src/click/__init__.py: F401
modified:.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
1ci:2 autoupdate_branch: "8.1.x"2 autoupdate_schedule: monthly3repos: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-fixer
modified:pyproject.toml+23 added
68 unmodified lines
69module = [70 "colorama.*",71]72ignore_missing_imports = true7374[tool.ruff]75extend-exclude = ["examples/"]76src = ["src"]77fix = true78show-fixes = true79show-source = true8081[tool.ruff.lint]82select = [83 "B", # flake8-bugbear84 "E", # pycodestyle error85 "F", # pyflakes86 "I", # isort87 "RUF", # ruff-specific rules88 "UP", # pyupgrade89 "W", # pycodestyle warning90]91ignore-init-module-imports = true9293[tool.ruff.lint.isort]94force-single-line = true95order-by-type = false