mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-13 06:24:16 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
72ad6dc953
commit
f4cd1ba0d6
813 changed files with 66015 additions and 58839 deletions
|
|
@ -4,14 +4,24 @@ This module MUST NOT try to import from anything within `pip._internal` to
|
|||
operate. This is expected to be importable from any/all files within the
|
||||
subpackage and, thus, should not depend on them.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import configparser
|
||||
import re
|
||||
from itertools import chain, groupby, repeat
|
||||
from typing import TYPE_CHECKING, Dict, List, Optional, Union
|
||||
from itertools import chain
|
||||
from itertools import groupby
|
||||
from itertools import repeat
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
from typing import Optional
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import Union
|
||||
|
||||
from pip._vendor.requests.models import Request, Response
|
||||
from pip._vendor.rich.console import Console, ConsoleOptions, RenderResult
|
||||
from pip._vendor.requests.models import Request
|
||||
from pip._vendor.requests.models import Response
|
||||
from pip._vendor.rich.console import Console
|
||||
from pip._vendor.rich.console import ConsoleOptions
|
||||
from pip._vendor.rich.console import RenderResult
|
||||
from pip._vendor.rich.markup import escape
|
||||
from pip._vendor.rich.text import Text
|
||||
|
||||
|
|
@ -27,11 +37,11 @@ if TYPE_CHECKING:
|
|||
# Scaffolding
|
||||
#
|
||||
def _is_kebab_case(s: str) -> bool:
|
||||
return re.match(r"^[a-z]+(-[a-z]+)*$", s) is not None
|
||||
return re.match(r'^[a-z]+(-[a-z]+)*$', s) is not None
|
||||
|
||||
|
||||
def _prefix_with_indent(
|
||||
s: Union[Text, str],
|
||||
s: Text | str,
|
||||
console: Console,
|
||||
*,
|
||||
prefix: str,
|
||||
|
|
@ -42,8 +52,8 @@ def _prefix_with_indent(
|
|||
else:
|
||||
text = console.render_str(s)
|
||||
|
||||
return console.render_str(prefix, overflow="ignore") + console.render_str(
|
||||
f"\n{indent}", overflow="ignore"
|
||||
return console.render_str(prefix, overflow='ignore') + console.render_str(
|
||||
f'\n{indent}', overflow='ignore',
|
||||
).join(text.split(allow_blank=True))
|
||||
|
||||
|
||||
|
|
@ -67,19 +77,19 @@ class DiagnosticPipError(PipError):
|
|||
def __init__(
|
||||
self,
|
||||
*,
|
||||
kind: 'Literal["error", "warning"]' = "error",
|
||||
reference: Optional[str] = None,
|
||||
message: Union[str, Text],
|
||||
context: Optional[Union[str, Text]],
|
||||
hint_stmt: Optional[Union[str, Text]],
|
||||
note_stmt: Optional[Union[str, Text]] = None,
|
||||
link: Optional[str] = None,
|
||||
kind: Literal["error", "warning"] = 'error',
|
||||
reference: str | None = None,
|
||||
message: str | Text,
|
||||
context: str | Text | None,
|
||||
hint_stmt: str | Text | None,
|
||||
note_stmt: str | Text | None = None,
|
||||
link: str | None = None,
|
||||
) -> None:
|
||||
# Ensure a proper reference is provided.
|
||||
if reference is None:
|
||||
assert hasattr(self, "reference"), "error reference not provided!"
|
||||
assert hasattr(self, 'reference'), 'error reference not provided!'
|
||||
reference = self.reference
|
||||
assert _is_kebab_case(reference), "error reference must be kebab-case!"
|
||||
assert _is_kebab_case(reference), 'error reference must be kebab-case!'
|
||||
|
||||
self.kind = kind
|
||||
self.reference = reference
|
||||
|
|
@ -92,17 +102,17 @@ class DiagnosticPipError(PipError):
|
|||
|
||||
self.link = link
|
||||
|
||||
super().__init__(f"<{self.__class__.__name__}: {self.reference}>")
|
||||
super().__init__(f'<{self.__class__.__name__}: {self.reference}>')
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return (
|
||||
f"<{self.__class__.__name__}("
|
||||
f"reference={self.reference!r}, "
|
||||
f"message={self.message!r}, "
|
||||
f"context={self.context!r}, "
|
||||
f"note_stmt={self.note_stmt!r}, "
|
||||
f"hint_stmt={self.hint_stmt!r}"
|
||||
")>"
|
||||
f'<{self.__class__.__name__}('
|
||||
f'reference={self.reference!r}, '
|
||||
f'message={self.message!r}, '
|
||||
f'context={self.context!r}, '
|
||||
f'note_stmt={self.note_stmt!r}, '
|
||||
f'hint_stmt={self.hint_stmt!r}'
|
||||
')>'
|
||||
)
|
||||
|
||||
def __rich_console__(
|
||||
|
|
@ -110,10 +120,10 @@ class DiagnosticPipError(PipError):
|
|||
console: Console,
|
||||
options: ConsoleOptions,
|
||||
) -> RenderResult:
|
||||
colour = "red" if self.kind == "error" else "yellow"
|
||||
colour = 'red' if self.kind == 'error' else 'yellow'
|
||||
|
||||
yield f"[{colour} bold]{self.kind}[/]: [bold]{self.reference}[/]"
|
||||
yield ""
|
||||
yield f'[{colour} bold]{self.kind}[/]: [bold]{self.reference}[/]'
|
||||
yield ''
|
||||
|
||||
if not options.ascii_only:
|
||||
# Present the main message, with relevant context indented.
|
||||
|
|
@ -121,49 +131,49 @@ class DiagnosticPipError(PipError):
|
|||
yield _prefix_with_indent(
|
||||
self.message,
|
||||
console,
|
||||
prefix=f"[{colour}]×[/] ",
|
||||
indent=f"[{colour}]│[/] ",
|
||||
prefix=f'[{colour}]×[/] ',
|
||||
indent=f'[{colour}]│[/] ',
|
||||
)
|
||||
yield _prefix_with_indent(
|
||||
self.context,
|
||||
console,
|
||||
prefix=f"[{colour}]╰─>[/] ",
|
||||
indent=f"[{colour}] [/] ",
|
||||
prefix=f'[{colour}]╰─>[/] ',
|
||||
indent=f'[{colour}] [/] ',
|
||||
)
|
||||
else:
|
||||
yield _prefix_with_indent(
|
||||
self.message,
|
||||
console,
|
||||
prefix="[red]×[/] ",
|
||||
indent=" ",
|
||||
prefix='[red]×[/] ',
|
||||
indent=' ',
|
||||
)
|
||||
else:
|
||||
yield self.message
|
||||
if self.context is not None:
|
||||
yield ""
|
||||
yield ''
|
||||
yield self.context
|
||||
|
||||
if self.note_stmt is not None or self.hint_stmt is not None:
|
||||
yield ""
|
||||
yield ''
|
||||
|
||||
if self.note_stmt is not None:
|
||||
yield _prefix_with_indent(
|
||||
self.note_stmt,
|
||||
console,
|
||||
prefix="[magenta bold]note[/]: ",
|
||||
indent=" ",
|
||||
prefix='[magenta bold]note[/]: ',
|
||||
indent=' ',
|
||||
)
|
||||
if self.hint_stmt is not None:
|
||||
yield _prefix_with_indent(
|
||||
self.hint_stmt,
|
||||
console,
|
||||
prefix="[cyan bold]hint[/]: ",
|
||||
indent=" ",
|
||||
prefix='[cyan bold]hint[/]: ',
|
||||
indent=' ',
|
||||
)
|
||||
|
||||
if self.link is not None:
|
||||
yield ""
|
||||
yield f"Link: {self.link}"
|
||||
yield ''
|
||||
yield f'Link: {self.link}'
|
||||
|
||||
|
||||
#
|
||||
|
|
@ -184,34 +194,34 @@ class UninstallationError(PipError):
|
|||
class MissingPyProjectBuildRequires(DiagnosticPipError):
|
||||
"""Raised when pyproject.toml has `build-system`, but no `build-system.requires`."""
|
||||
|
||||
reference = "missing-pyproject-build-system-requires"
|
||||
reference = 'missing-pyproject-build-system-requires'
|
||||
|
||||
def __init__(self, *, package: str) -> None:
|
||||
super().__init__(
|
||||
message=f"Can not process {escape(package)}",
|
||||
message=f'Can not process {escape(package)}',
|
||||
context=Text(
|
||||
"This package has an invalid pyproject.toml file.\n"
|
||||
"The [build-system] table is missing the mandatory `requires` key."
|
||||
'This package has an invalid pyproject.toml file.\n'
|
||||
'The [build-system] table is missing the mandatory `requires` key.',
|
||||
),
|
||||
note_stmt="This is an issue with the package mentioned above, not pip.",
|
||||
hint_stmt=Text("See PEP 518 for the detailed specification."),
|
||||
note_stmt='This is an issue with the package mentioned above, not pip.',
|
||||
hint_stmt=Text('See PEP 518 for the detailed specification.'),
|
||||
)
|
||||
|
||||
|
||||
class InvalidPyProjectBuildRequires(DiagnosticPipError):
|
||||
"""Raised when pyproject.toml an invalid `build-system.requires`."""
|
||||
|
||||
reference = "invalid-pyproject-build-system-requires"
|
||||
reference = 'invalid-pyproject-build-system-requires'
|
||||
|
||||
def __init__(self, *, package: str, reason: str) -> None:
|
||||
super().__init__(
|
||||
message=f"Can not process {escape(package)}",
|
||||
message=f'Can not process {escape(package)}',
|
||||
context=Text(
|
||||
"This package has an invalid `build-system.requires` key in "
|
||||
f"pyproject.toml.\n{reason}"
|
||||
'This package has an invalid `build-system.requires` key in '
|
||||
f'pyproject.toml.\n{reason}',
|
||||
),
|
||||
note_stmt="This is an issue with the package mentioned above, not pip.",
|
||||
hint_stmt=Text("See PEP 518 for the detailed specification."),
|
||||
note_stmt='This is an issue with the package mentioned above, not pip.',
|
||||
hint_stmt=Text('See PEP 518 for the detailed specification.'),
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -226,7 +236,7 @@ class NoneMetadataError(PipError):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
dist: "BaseDistribution",
|
||||
dist: BaseDistribution,
|
||||
metadata_name: str,
|
||||
) -> None:
|
||||
"""
|
||||
|
|
@ -240,7 +250,7 @@ class NoneMetadataError(PipError):
|
|||
def __str__(self) -> str:
|
||||
# Use `dist` in the error message because its stringification
|
||||
# includes more information, like the version and location.
|
||||
return "None {} metadata found for distribution: {}".format(
|
||||
return 'None {} metadata found for distribution: {}'.format(
|
||||
self.metadata_name,
|
||||
self.dist,
|
||||
)
|
||||
|
|
@ -250,13 +260,13 @@ class UserInstallationInvalid(InstallationError):
|
|||
"""A --user install is requested on an environment without user site."""
|
||||
|
||||
def __str__(self) -> str:
|
||||
return "User base directory is not specified"
|
||||
return 'User base directory is not specified'
|
||||
|
||||
|
||||
class InvalidSchemeCombination(InstallationError):
|
||||
def __str__(self) -> str:
|
||||
before = ", ".join(str(a) for a in self.args[:-1])
|
||||
return f"Cannot set {before} and {self.args[-1]} together"
|
||||
before = ', '.join(str(a) for a in self.args[:-1])
|
||||
return f'Cannot set {before} and {self.args[-1]} together'
|
||||
|
||||
|
||||
class DistributionNotFound(InstallationError):
|
||||
|
|
@ -288,7 +298,7 @@ class NetworkConnectionError(PipError):
|
|||
"""HTTP connection error"""
|
||||
|
||||
def __init__(
|
||||
self, error_msg: str, response: Response = None, request: Request = None
|
||||
self, error_msg: str, response: Response = None, request: Request = None,
|
||||
) -> None:
|
||||
"""
|
||||
Initialize NetworkConnectionError with `request` and `response`
|
||||
|
|
@ -298,9 +308,9 @@ class NetworkConnectionError(PipError):
|
|||
self.request = request
|
||||
self.error_msg = error_msg
|
||||
if (
|
||||
self.response is not None
|
||||
and not self.request
|
||||
and hasattr(response, "request")
|
||||
self.response is not None and
|
||||
not self.request and
|
||||
hasattr(response, 'request')
|
||||
):
|
||||
self.request = self.response.request
|
||||
super().__init__(error_msg, response, request)
|
||||
|
|
@ -337,7 +347,7 @@ class MetadataInconsistent(InstallationError):
|
|||
"""
|
||||
|
||||
def __init__(
|
||||
self, ireq: "InstallRequirement", field: str, f_val: str, m_val: str
|
||||
self, ireq: InstallRequirement, field: str, f_val: str, m_val: str,
|
||||
) -> None:
|
||||
self.ireq = ireq
|
||||
self.field = field
|
||||
|
|
@ -346,8 +356,8 @@ class MetadataInconsistent(InstallationError):
|
|||
|
||||
def __str__(self) -> str:
|
||||
template = (
|
||||
"Requested {} has inconsistent {}: "
|
||||
"filename has {!r}, but metadata has {!r}"
|
||||
'Requested {} has inconsistent {}: '
|
||||
'filename has {!r}, but metadata has {!r}'
|
||||
)
|
||||
return template.format(self.ireq, self.field, self.f_val, self.m_val)
|
||||
|
||||
|
|
@ -355,48 +365,48 @@ class MetadataInconsistent(InstallationError):
|
|||
class LegacyInstallFailure(DiagnosticPipError):
|
||||
"""Error occurred while executing `setup.py install`"""
|
||||
|
||||
reference = "legacy-install-failure"
|
||||
reference = 'legacy-install-failure'
|
||||
|
||||
def __init__(self, package_details: str) -> None:
|
||||
super().__init__(
|
||||
message="Encountered error while trying to install package.",
|
||||
message='Encountered error while trying to install package.',
|
||||
context=package_details,
|
||||
hint_stmt="See above for output from the failure.",
|
||||
note_stmt="This is an issue with the package mentioned above, not pip.",
|
||||
hint_stmt='See above for output from the failure.',
|
||||
note_stmt='This is an issue with the package mentioned above, not pip.',
|
||||
)
|
||||
|
||||
|
||||
class InstallationSubprocessError(DiagnosticPipError, InstallationError):
|
||||
"""A subprocess call failed."""
|
||||
|
||||
reference = "subprocess-exited-with-error"
|
||||
reference = 'subprocess-exited-with-error'
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
command_description: str,
|
||||
exit_code: int,
|
||||
output_lines: Optional[List[str]],
|
||||
output_lines: list[str] | None,
|
||||
) -> None:
|
||||
if output_lines is None:
|
||||
output_prompt = Text("See above for output.")
|
||||
output_prompt = Text('See above for output.')
|
||||
else:
|
||||
output_prompt = (
|
||||
Text.from_markup(f"[red][{len(output_lines)} lines of output][/]\n")
|
||||
+ Text("".join(output_lines))
|
||||
+ Text.from_markup(R"[red]\[end of output][/]")
|
||||
Text.from_markup(f'[red][{len(output_lines)} lines of output][/]\n') +
|
||||
Text(''.join(output_lines)) +
|
||||
Text.from_markup(R'[red]\[end of output][/]')
|
||||
)
|
||||
|
||||
super().__init__(
|
||||
message=(
|
||||
f"[green]{escape(command_description)}[/] did not run successfully.\n"
|
||||
f"exit code: {exit_code}"
|
||||
f'[green]{escape(command_description)}[/] did not run successfully.\n'
|
||||
f'exit code: {exit_code}'
|
||||
),
|
||||
context=output_prompt,
|
||||
hint_stmt=None,
|
||||
note_stmt=(
|
||||
"This error originates from a subprocess, and is likely not a "
|
||||
"problem with pip."
|
||||
'This error originates from a subprocess, and is likely not a '
|
||||
'problem with pip.'
|
||||
),
|
||||
)
|
||||
|
||||
|
|
@ -404,11 +414,11 @@ class InstallationSubprocessError(DiagnosticPipError, InstallationError):
|
|||
self.exit_code = exit_code
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.command_description} exited with {self.exit_code}"
|
||||
return f'{self.command_description} exited with {self.exit_code}'
|
||||
|
||||
|
||||
class MetadataGenerationFailed(InstallationSubprocessError, InstallationError):
|
||||
reference = "metadata-generation-failed"
|
||||
reference = 'metadata-generation-failed'
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
|
@ -416,23 +426,23 @@ class MetadataGenerationFailed(InstallationSubprocessError, InstallationError):
|
|||
package_details: str,
|
||||
) -> None:
|
||||
super(InstallationSubprocessError, self).__init__(
|
||||
message="Encountered error while generating package metadata.",
|
||||
message='Encountered error while generating package metadata.',
|
||||
context=escape(package_details),
|
||||
hint_stmt="See above for details.",
|
||||
note_stmt="This is an issue with the package mentioned above, not pip.",
|
||||
hint_stmt='See above for details.',
|
||||
note_stmt='This is an issue with the package mentioned above, not pip.',
|
||||
)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return "metadata generation failed"
|
||||
return 'metadata generation failed'
|
||||
|
||||
|
||||
class HashErrors(InstallationError):
|
||||
"""Multiple HashError instances rolled into one for reporting"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.errors: List["HashError"] = []
|
||||
self.errors: list[HashError] = []
|
||||
|
||||
def append(self, error: "HashError") -> None:
|
||||
def append(self, error: HashError) -> None:
|
||||
self.errors.append(error)
|
||||
|
||||
def __str__(self) -> str:
|
||||
|
|
@ -442,8 +452,8 @@ class HashErrors(InstallationError):
|
|||
lines.append(cls.head)
|
||||
lines.extend(e.body() for e in errors_of_cls)
|
||||
if lines:
|
||||
return "\n".join(lines)
|
||||
return ""
|
||||
return '\n'.join(lines)
|
||||
return ''
|
||||
|
||||
def __bool__(self) -> bool:
|
||||
return bool(self.errors)
|
||||
|
|
@ -466,8 +476,8 @@ class HashError(InstallationError):
|
|||
|
||||
"""
|
||||
|
||||
req: Optional["InstallRequirement"] = None
|
||||
head = ""
|
||||
req: InstallRequirement | None = None
|
||||
head = ''
|
||||
order: int = -1
|
||||
|
||||
def body(self) -> str:
|
||||
|
|
@ -480,10 +490,10 @@ class HashError(InstallationError):
|
|||
its link already populated by the resolver's _populate_link().
|
||||
|
||||
"""
|
||||
return f" {self._requirement_name()}"
|
||||
return f' {self._requirement_name()}'
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.head}\n{self.body()}"
|
||||
return f'{self.head}\n{self.body()}'
|
||||
|
||||
def _requirement_name(self) -> str:
|
||||
"""Return a description of the requirement that triggered me.
|
||||
|
|
@ -492,7 +502,7 @@ class HashError(InstallationError):
|
|||
line numbers
|
||||
|
||||
"""
|
||||
return str(self.req) if self.req else "unknown package"
|
||||
return str(self.req) if self.req else 'unknown package'
|
||||
|
||||
|
||||
class VcsHashUnsupported(HashError):
|
||||
|
|
@ -502,7 +512,7 @@ class VcsHashUnsupported(HashError):
|
|||
order = 0
|
||||
head = (
|
||||
"Can't verify hashes for these requirements because we don't "
|
||||
"have a way to hash version control repositories:"
|
||||
'have a way to hash version control repositories:'
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -513,7 +523,7 @@ class DirectoryUrlHashUnsupported(HashError):
|
|||
order = 1
|
||||
head = (
|
||||
"Can't verify hashes for these file:// requirements because they "
|
||||
"point to directories:"
|
||||
'point to directories:'
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -522,13 +532,13 @@ class HashMissing(HashError):
|
|||
|
||||
order = 2
|
||||
head = (
|
||||
"Hashes are required in --require-hashes mode, but they are "
|
||||
"missing from some requirements. Here is a list of those "
|
||||
"requirements along with the hashes their downloaded archives "
|
||||
"actually had. Add lines like these to your requirements files to "
|
||||
"prevent tampering. (If you did not enable --require-hashes "
|
||||
"manually, note that it turns on automatically when any package "
|
||||
"has a hash.)"
|
||||
'Hashes are required in --require-hashes mode, but they are '
|
||||
'missing from some requirements. Here is a list of those '
|
||||
'requirements along with the hashes their downloaded archives '
|
||||
'actually had. Add lines like these to your requirements files to '
|
||||
'prevent tampering. (If you did not enable --require-hashes '
|
||||
'manually, note that it turns on automatically when any package '
|
||||
'has a hash.)'
|
||||
)
|
||||
|
||||
def __init__(self, gotten_hash: str) -> None:
|
||||
|
|
@ -552,10 +562,10 @@ class HashMissing(HashError):
|
|||
if self.req.original_link
|
||||
# In case someone feeds something downright stupid
|
||||
# to InstallRequirement's constructor.
|
||||
else getattr(self.req, "req", None)
|
||||
else getattr(self.req, 'req', None)
|
||||
)
|
||||
return " {} --hash={}:{}".format(
|
||||
package or "unknown package", FAVORITE_HASH, self.gotten_hash
|
||||
return ' {} --hash={}:{}'.format(
|
||||
package or 'unknown package', FAVORITE_HASH, self.gotten_hash,
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -565,8 +575,8 @@ class HashUnpinned(HashError):
|
|||
|
||||
order = 3
|
||||
head = (
|
||||
"In --require-hashes mode, all requirements must have their "
|
||||
"versions pinned with ==. These do not:"
|
||||
'In --require-hashes mode, all requirements must have their '
|
||||
'versions pinned with ==. These do not:'
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -582,13 +592,13 @@ class HashMismatch(HashError):
|
|||
|
||||
order = 4
|
||||
head = (
|
||||
"THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS "
|
||||
"FILE. If you have updated the package versions, please update "
|
||||
"the hashes. Otherwise, examine the package contents carefully; "
|
||||
"someone may have tampered with them."
|
||||
'THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS '
|
||||
'FILE. If you have updated the package versions, please update '
|
||||
'the hashes. Otherwise, examine the package contents carefully; '
|
||||
'someone may have tampered with them.'
|
||||
)
|
||||
|
||||
def __init__(self, allowed: Dict[str, List[str]], gots: Dict[str, "_Hash"]) -> None:
|
||||
def __init__(self, allowed: dict[str, list[str]], gots: dict[str, _Hash]) -> None:
|
||||
"""
|
||||
:param allowed: A dict of algorithm names pointing to lists of allowed
|
||||
hex digests
|
||||
|
|
@ -599,7 +609,7 @@ class HashMismatch(HashError):
|
|||
self.gots = gots
|
||||
|
||||
def body(self) -> str:
|
||||
return " {}:\n{}".format(self._requirement_name(), self._hash_comparison())
|
||||
return f' {self._requirement_name()}:\n{self._hash_comparison()}'
|
||||
|
||||
def _hash_comparison(self) -> str:
|
||||
"""
|
||||
|
|
@ -613,21 +623,21 @@ class HashMismatch(HashError):
|
|||
|
||||
"""
|
||||
|
||||
def hash_then_or(hash_name: str) -> "chain[str]":
|
||||
def hash_then_or(hash_name: str) -> chain[str]:
|
||||
# For now, all the decent hashes have 6-char names, so we can get
|
||||
# away with hard-coding space literals.
|
||||
return chain([hash_name], repeat(" or"))
|
||||
return chain([hash_name], repeat(' or'))
|
||||
|
||||
lines: List[str] = []
|
||||
lines: list[str] = []
|
||||
for hash_name, expecteds in self.allowed.items():
|
||||
prefix = hash_then_or(hash_name)
|
||||
lines.extend(
|
||||
(" Expected {} {}".format(next(prefix), e)) for e in expecteds
|
||||
(f' Expected {next(prefix)} {e}') for e in expecteds
|
||||
)
|
||||
lines.append(
|
||||
" Got {}\n".format(self.gots[hash_name].hexdigest())
|
||||
f' Got {self.gots[hash_name].hexdigest()}\n',
|
||||
)
|
||||
return "\n".join(lines)
|
||||
return '\n'.join(lines)
|
||||
|
||||
|
||||
class UnsupportedPythonVersion(InstallationError):
|
||||
|
|
@ -640,9 +650,9 @@ class ConfigurationFileCouldNotBeLoaded(ConfigurationError):
|
|||
|
||||
def __init__(
|
||||
self,
|
||||
reason: str = "could not be loaded",
|
||||
fname: Optional[str] = None,
|
||||
error: Optional[configparser.Error] = None,
|
||||
reason: str = 'could not be loaded',
|
||||
fname: str | None = None,
|
||||
error: configparser.Error | None = None,
|
||||
) -> None:
|
||||
super().__init__(error)
|
||||
self.reason = reason
|
||||
|
|
@ -651,8 +661,8 @@ class ConfigurationFileCouldNotBeLoaded(ConfigurationError):
|
|||
|
||||
def __str__(self) -> str:
|
||||
if self.fname is not None:
|
||||
message_part = f" in {self.fname}."
|
||||
message_part = f' in {self.fname}.'
|
||||
else:
|
||||
assert self.error is not None
|
||||
message_part = f".\n{self.error}\n"
|
||||
return f"Configuration file {self.reason}{message_part}"
|
||||
message_part = f'.\n{self.error}\n'
|
||||
return f'Configuration file {self.reason}{message_part}'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue