[pre-commit.ci] pre-commit autoupdate (#8547)
* [pre-commit.ci] pre-commit autoupdate * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Ran Benita <ran@unusedvar.com>
This commit is contained in:
parent
4b214a6049
commit
d200598de9
|
@ -34,7 +34,7 @@ repos:
|
|||
- id: reorder-python-imports
|
||||
args: ['--application-directories=.:src', --py36-plus]
|
||||
- repo: https://github.com/asottile/pyupgrade
|
||||
rev: v2.11.0
|
||||
rev: v2.12.0
|
||||
hooks:
|
||||
- id: pyupgrade
|
||||
args: [--py36-plus]
|
||||
|
|
|
@ -968,7 +968,7 @@ class TerminalRepr:
|
|||
return io.getvalue().strip()
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return "<{} instance at {:0x}>".format(self.__class__, id(self))
|
||||
return f"<{self.__class__} instance at {id(self):0x}>"
|
||||
|
||||
def toterminal(self, tw: TerminalWriter) -> None:
|
||||
raise NotImplementedError()
|
||||
|
|
|
@ -12,7 +12,7 @@ def _try_repr_or_str(obj: object) -> str:
|
|||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
except BaseException:
|
||||
return '{}("{}")'.format(type(obj).__name__, obj)
|
||||
return f'{type(obj).__name__}("{obj}")'
|
||||
|
||||
|
||||
def _format_repr_exception(exc: BaseException, obj: object) -> str:
|
||||
|
@ -21,7 +21,7 @@ def _format_repr_exception(exc: BaseException, obj: object) -> str:
|
|||
except (KeyboardInterrupt, SystemExit):
|
||||
raise
|
||||
except BaseException as exc:
|
||||
exc_info = "unpresentable exception ({})".format(_try_repr_or_str(exc))
|
||||
exc_info = f"unpresentable exception ({_try_repr_or_str(exc)})"
|
||||
return "<[{} raised in repr()] {} object at 0x{:x}>".format(
|
||||
exc_info, type(obj).__name__, id(obj)
|
||||
)
|
||||
|
|
|
@ -418,4 +418,4 @@ else:
|
|||
#
|
||||
# This also work for Enums (if you use `is` to compare) and Literals.
|
||||
def assert_never(value: "NoReturn") -> "NoReturn":
|
||||
assert False, "Unhandled value: {} ({})".format(value, type(value).__name__)
|
||||
assert False, f"Unhandled value: {value} ({type(value).__name__})"
|
||||
|
|
|
@ -721,7 +721,7 @@ class PytestPluginManager(PluginManager):
|
|||
__import__(importspec)
|
||||
except ImportError as e:
|
||||
raise ImportError(
|
||||
'Error importing plugin "{}": {}'.format(modname, str(e.args[0]))
|
||||
f'Error importing plugin "{modname}": {e.args[0]}'
|
||||
).with_traceback(e.__traceback__) from e
|
||||
|
||||
except Skipped as e:
|
||||
|
|
|
@ -859,7 +859,7 @@ class FixtureLookupError(LookupError):
|
|||
error_msg = "file %s, line %s: source code not available"
|
||||
addline(error_msg % (fspath, lineno + 1))
|
||||
else:
|
||||
addline("file {}, line {}".format(fspath, lineno + 1))
|
||||
addline(f"file {fspath}, line {lineno + 1}")
|
||||
for i, line in enumerate(lines):
|
||||
line = line.rstrip()
|
||||
addline(" " + line)
|
||||
|
@ -908,7 +908,7 @@ class FixtureLookupErrorRepr(TerminalRepr):
|
|||
lines = self.errorstring.split("\n")
|
||||
if lines:
|
||||
tw.line(
|
||||
"{} {}".format(FormattedExcinfo.fail_marker, lines[0].strip()),
|
||||
f"{FormattedExcinfo.fail_marker} {lines[0].strip()}",
|
||||
red=True,
|
||||
)
|
||||
for line in lines[1:]:
|
||||
|
@ -922,7 +922,7 @@ class FixtureLookupErrorRepr(TerminalRepr):
|
|||
|
||||
def fail_fixturefunc(fixturefunc, msg: str) -> "NoReturn":
|
||||
fs, lineno = getfslineno(fixturefunc)
|
||||
location = "{}:{}".format(fs, lineno + 1)
|
||||
location = f"{fs}:{lineno + 1}"
|
||||
source = _pytest._code.Source(fixturefunc)
|
||||
fail(msg + ":\n\n" + str(source.indent()) + "\n" + location, pytrace=False)
|
||||
|
||||
|
|
|
@ -294,7 +294,7 @@ def wrap_session(
|
|||
except exit.Exception as exc:
|
||||
if exc.returncode is not None:
|
||||
session.exitstatus = exc.returncode
|
||||
sys.stderr.write("{}: {}\n".format(type(exc).__name__, exc))
|
||||
sys.stderr.write(f"{type(exc).__name__}: {exc}\n")
|
||||
else:
|
||||
if isinstance(excinfo.value, SystemExit):
|
||||
sys.stderr.write("mainloop: caught unexpected SystemExit!\n")
|
||||
|
@ -311,7 +311,7 @@ def wrap_session(
|
|||
except exit.Exception as exc:
|
||||
if exc.returncode is not None:
|
||||
session.exitstatus = exc.returncode
|
||||
sys.stderr.write("{}: {}\n".format(type(exc).__name__, exc))
|
||||
sys.stderr.write(f"{type(exc).__name__}: {exc}\n")
|
||||
config._ensure_unconfigure()
|
||||
return session.exitstatus
|
||||
|
||||
|
@ -718,7 +718,7 @@ class Session(nodes.FSCollector):
|
|||
# If it's a directory argument, recurse and look for any Subpackages.
|
||||
# Let the Package collector deal with subnodes, don't collect here.
|
||||
if argpath.is_dir():
|
||||
assert not names, "invalid arg {!r}".format((argpath, names))
|
||||
assert not names, f"invalid arg {(argpath, names)!r}"
|
||||
|
||||
seen_dirs: Set[Path] = set()
|
||||
for direntry in visit(str(argpath), self._recurse):
|
||||
|
|
|
@ -103,7 +103,7 @@ class Scanner:
|
|||
else:
|
||||
raise ParseError(
|
||||
pos + 1,
|
||||
'unexpected character "{}"'.format(input[pos]),
|
||||
f'unexpected character "{input[pos]}"',
|
||||
)
|
||||
yield Token(TokenType.EOF, "", pos)
|
||||
|
||||
|
|
|
@ -99,9 +99,7 @@ class ParameterSet(
|
|||
|
||||
if id is not None:
|
||||
if not isinstance(id, str):
|
||||
raise TypeError(
|
||||
"Expected id to be a string, got {}: {!r}".format(type(id), id)
|
||||
)
|
||||
raise TypeError(f"Expected id to be a string, got {type(id)}: {id!r}")
|
||||
id = ascii_escaped(id)
|
||||
return cls(values, marks, id)
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ def create_new_paste(contents: Union[str, bytes]) -> str:
|
|||
return "bad response: %s" % exc_info
|
||||
m = re.search(r'href="/raw/(\w+)"', response)
|
||||
if m:
|
||||
return "{}/show/{}".format(url, m.group(1))
|
||||
return f"{url}/show/{m.group(1)}"
|
||||
else:
|
||||
return "bad response: invalid format ('" + response + "')"
|
||||
|
||||
|
|
|
@ -500,9 +500,7 @@ def import_path(
|
|||
spec = importlib.util.spec_from_file_location(module_name, str(path))
|
||||
|
||||
if spec is None:
|
||||
raise ImportError(
|
||||
"Can't find module {} at location {}".format(module_name, str(path))
|
||||
)
|
||||
raise ImportError(f"Can't find module {module_name} at location {path}")
|
||||
mod = importlib.util.module_from_spec(spec)
|
||||
sys.modules[module_name] = mod
|
||||
spec.loader.exec_module(mod) # type: ignore[union-attr]
|
||||
|
|
|
@ -1865,7 +1865,7 @@ class LineMatcher:
|
|||
Match lines consecutively?
|
||||
"""
|
||||
if not isinstance(lines2, collections.abc.Sequence):
|
||||
raise TypeError("invalid type for lines2: {}".format(type(lines2).__name__))
|
||||
raise TypeError(f"invalid type for lines2: {type(lines2).__name__}")
|
||||
lines2 = self._getlines(lines2)
|
||||
lines1 = self.lines[:]
|
||||
extralines = []
|
||||
|
|
|
@ -1400,7 +1400,7 @@ def idmaker(
|
|||
# Suffix non-unique IDs to make them unique.
|
||||
for index, test_id in enumerate(resolved_ids):
|
||||
if test_id_counts[test_id] > 1:
|
||||
resolved_ids[index] = "{}{}".format(test_id, test_id_suffixes[test_id])
|
||||
resolved_ids[index] = f"{test_id}{test_id_suffixes[test_id]}"
|
||||
test_id_suffixes[test_id] += 1
|
||||
|
||||
return resolved_ids
|
||||
|
@ -1449,7 +1449,7 @@ def _show_fixtures_per_test(config: Config, session: Session) -> None:
|
|||
tw.line()
|
||||
tw.sep("-", f"fixtures used by {item.name}")
|
||||
# TODO: Fix this type ignore.
|
||||
tw.sep("-", "({})".format(get_best_relpath(item.function))) # type: ignore[attr-defined]
|
||||
tw.sep("-", f"({get_best_relpath(item.function)})") # type: ignore[attr-defined]
|
||||
# dict key not used in loop but needed for sorting.
|
||||
for _, fixturedefs in sorted(info.name2fixturedefs.items()):
|
||||
assert fixturedefs is not None
|
||||
|
|
|
@ -733,9 +733,7 @@ def raises(
|
|||
else:
|
||||
func = args[0]
|
||||
if not callable(func):
|
||||
raise TypeError(
|
||||
"{!r} object (type: {}) must be callable".format(func, type(func))
|
||||
)
|
||||
raise TypeError(f"{func!r} object (type: {type(func)}) must be callable")
|
||||
try:
|
||||
func(*args[1:], **kwargs)
|
||||
except expected_exception as e:
|
||||
|
|
|
@ -149,9 +149,7 @@ def warns(
|
|||
else:
|
||||
func = args[0]
|
||||
if not callable(func):
|
||||
raise TypeError(
|
||||
"{!r} object (type: {}) must be callable".format(func, type(func))
|
||||
)
|
||||
raise TypeError(f"{func!r} object (type: {type(func)}) must be callable")
|
||||
with WarningsChecker(expected_warning, _ispytest=True):
|
||||
return func(*args[1:], **kwargs)
|
||||
|
||||
|
|
|
@ -79,7 +79,7 @@ def _show_fixture_action(fixturedef: FixtureDef[object], msg: str) -> None:
|
|||
tw.write(" (fixtures used: {})".format(", ".join(deps)))
|
||||
|
||||
if hasattr(fixturedef, "cached_param"):
|
||||
tw.write("[{}]".format(saferepr(fixturedef.cached_param, maxsize=42))) # type: ignore[attr-defined]
|
||||
tw.write(f"[{saferepr(fixturedef.cached_param, maxsize=42)}]") # type: ignore[attr-defined]
|
||||
|
||||
tw.flush()
|
||||
|
||||
|
|
|
@ -588,7 +588,7 @@ class TerminalReporter:
|
|||
if self.verbosity <= 0 and self._show_progress_info:
|
||||
if self._show_progress_info == "count":
|
||||
num_tests = self._session.testscollected
|
||||
progress_length = len(" [{}/{}]".format(str(num_tests), str(num_tests)))
|
||||
progress_length = len(f" [{num_tests}/{num_tests}]")
|
||||
else:
|
||||
progress_length = len(" [100%]")
|
||||
|
||||
|
@ -610,7 +610,7 @@ class TerminalReporter:
|
|||
if self._show_progress_info == "count":
|
||||
if collected:
|
||||
progress = self._progress_nodeids_reported
|
||||
counter_format = "{{:{}d}}".format(len(str(collected)))
|
||||
counter_format = f"{{:{len(str(collected))}d}}"
|
||||
format_string = f" [{counter_format}/{{}}]"
|
||||
return format_string.format(len(progress), collected)
|
||||
return f" [ {collected} / {collected} ]"
|
||||
|
@ -704,7 +704,7 @@ class TerminalReporter:
|
|||
pypy_version_info = getattr(sys, "pypy_version_info", None)
|
||||
if pypy_version_info:
|
||||
verinfo = ".".join(map(str, pypy_version_info[:3]))
|
||||
msg += "[pypy-{}-{}]".format(verinfo, pypy_version_info[3])
|
||||
msg += f"[pypy-{verinfo}-{pypy_version_info[3]}]"
|
||||
msg += ", pytest-{}, py-{}, pluggy-{}".format(
|
||||
_pytest._version.version, py.__version__, pluggy.__version__
|
||||
)
|
||||
|
@ -1066,7 +1066,7 @@ class TerminalReporter:
|
|||
msg = ", ".join(line_parts)
|
||||
|
||||
main_markup = {main_color: True}
|
||||
duration = " in {}".format(format_session_duration(session_duration))
|
||||
duration = f" in {format_session_duration(session_duration)}"
|
||||
duration_with_markup = self._tw.markup(duration, **main_markup)
|
||||
if display_sep:
|
||||
fullwidth += len(duration_with_markup) - len(duration)
|
||||
|
|
|
@ -188,7 +188,7 @@ class TestGeneralUsage:
|
|||
result.stderr.fnmatch_lines(
|
||||
[
|
||||
f"ERROR: not found: {p2}",
|
||||
"(no name {!r} in any of [[][]])".format(str(p2)),
|
||||
f"(no name {str(p2)!r} in any of [[][]])",
|
||||
"",
|
||||
]
|
||||
)
|
||||
|
|
|
@ -144,7 +144,7 @@ class TestRaises:
|
|||
try:
|
||||
pytest.raises(ValueError, int, "0")
|
||||
except pytest.fail.Exception as e:
|
||||
assert e.msg == "DID NOT RAISE {}".format(repr(ValueError))
|
||||
assert e.msg == f"DID NOT RAISE {repr(ValueError)}"
|
||||
else:
|
||||
assert False, "Expected pytest.raises.Exception"
|
||||
|
||||
|
@ -152,7 +152,7 @@ class TestRaises:
|
|||
with pytest.raises(ValueError):
|
||||
pass
|
||||
except pytest.fail.Exception as e:
|
||||
assert e.msg == "DID NOT RAISE {}".format(repr(ValueError))
|
||||
assert e.msg == f"DID NOT RAISE {repr(ValueError)}"
|
||||
else:
|
||||
assert False, "Expected pytest.raises.Exception"
|
||||
|
||||
|
|
|
@ -772,7 +772,7 @@ class TestStackLevel:
|
|||
# with stacklevel=2 the warning should originate from the above created test file
|
||||
result.stdout.fnmatch_lines_random(
|
||||
[
|
||||
"*{testfile}:3*".format(testfile=str(testfile)),
|
||||
f"*{testfile}:3*",
|
||||
"*Unknown pytest.mark.unknown*",
|
||||
]
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue