Skip to content

Commit

Permalink
Rename exceptions to have Error suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
Secrus authored and radoering committed Sep 29, 2024
1 parent 5f9fb5f commit ab2f5a2
Show file tree
Hide file tree
Showing 43 changed files with 191 additions and 189 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ extend-select = [
ignore = [
"B904", # use 'raise ... from err'
"B905", # use explicit 'strict=' parameter with 'zip()'
"N818", # Exception name should be named with an Error suffix
]
extend-safe-fixes = [
"TCH", # move import from and to TYPE_CHECKING blocks
Expand Down
4 changes: 2 additions & 2 deletions src/poetry/console/commands/group_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from poetry.core.packages.dependency_group import MAIN_GROUP

from poetry.console.commands.command import Command
from poetry.console.exceptions import GroupNotFound
from poetry.console.exceptions import GroupNotFoundError


if TYPE_CHECKING:
Expand Down Expand Up @@ -128,4 +128,4 @@ def _validate_group_options(self, group_options: dict[str, set[str]]) -> None:
for opt in sorted(invalid_options[group])
)
message_parts.append(f"{group} (via {opts})")
raise GroupNotFound(f"Group(s) not found: {', '.join(message_parts)}")
raise GroupNotFoundError(f"Group(s) not found: {', '.join(message_parts)}")
2 changes: 1 addition & 1 deletion src/poetry/console/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class PoetryConsoleError(CleoError):
pass


class GroupNotFound(PoetryConsoleError):
class GroupNotFoundError(PoetryConsoleError):
pass
2 changes: 1 addition & 1 deletion src/poetry/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations


class PoetryException(Exception):
class PoetryError(Exception):
pass
4 changes: 2 additions & 2 deletions src/poetry/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from poetry.core.packages.dependency_group import MAIN_GROUP

from poetry.config.config import Config
from poetry.exceptions import PoetryException
from poetry.exceptions import PoetryError
from poetry.json import validate_object
from poetry.packages.locker import Locker
from poetry.plugins.plugin import Plugin
Expand Down Expand Up @@ -155,7 +155,7 @@ def create_pool(
)

if not pool.repositories:
raise PoetryException(
raise PoetryError(
"At least one source must not be configured as 'explicit'."
)

Expand Down
32 changes: 17 additions & 15 deletions src/poetry/inspection/lazy_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ class LazyWheelUnsupportedError(Exception):
"""Raised when a lazy wheel is unsupported."""


class HTTPRangeRequestUnsupported(LazyWheelUnsupportedError):
class HTTPRangeRequestUnsupportedError(LazyWheelUnsupportedError):
"""Raised when the remote server appears unable to support byte ranges."""


class HTTPRangeRequestNotRespected(LazyWheelUnsupportedError):
class HTTPRangeRequestNotRespectedError(LazyWheelUnsupportedError):
"""Raised when the remote server tells us that it supports byte ranges
but does not respect a respective request."""


class UnsupportedWheel(LazyWheelUnsupportedError):
class UnsupportedWheelError(LazyWheelUnsupportedError):
"""Unsupported wheel."""


class InvalidWheel(LazyWheelUnsupportedError):
class InvalidWheelError(LazyWheelUnsupportedError):
"""Invalid (e.g. corrupt) wheel."""

def __init__(self, location: str, name: str) -> None:
Expand All @@ -77,8 +77,8 @@ def metadata_from_wheel_url(
This uses HTTP range requests to only fetch the portion of the wheel
containing metadata, just enough for the object to be constructed.
:raises HTTPRangeRequestUnsupported: if range requests are unsupported for ``url``.
:raises InvalidWheel: if the zip file contents could not be parsed.
:raises HTTPRangeRequestUnsupportedError: if range requests are unsupported for ``url``.
:raises InvalidWheelError: if the zip file contents could not be parsed.
"""
try:
# After context manager exit, wheel.name will point to a deleted file path.
Expand All @@ -89,11 +89,11 @@ def metadata_from_wheel_url(
metadata, _ = parse_email(metadata_bytes)
return metadata

except (BadZipFile, UnsupportedWheel):
except (BadZipFile, UnsupportedWheelError):
# We assume that these errors have occurred because the wheel contents
# themselves are invalid, not because we've messed up our bookkeeping
# and produced an invalid file.
raise InvalidWheel(url, name)
raise InvalidWheelError(url, name)
except Exception as e:
if isinstance(e, LazyWheelUnsupportedError):
# this is expected when the code handles issues with lazy wheel metadata retrieval correctly
Expand Down Expand Up @@ -288,7 +288,7 @@ class LazyFileOverHTTP(ReadOnlyIOWrapper):
This uses HTTP range requests to lazily fetch the file's content into a temporary
file. If such requests are not supported by the server, raises
``HTTPRangeRequestUnsupported`` in the ``__enter__`` method."""
``HTTPRangeRequestUnsupportedError`` in the ``__enter__`` method."""

def __init__(
self,
Expand Down Expand Up @@ -401,7 +401,7 @@ def _reset_content(self) -> None:
def _content_length_from_head(self) -> int:
"""Performs a HEAD request to extract the Content-Length.
:raises HTTPRangeRequestUnsupported: if the response fails to indicate support
:raises HTTPRangeRequestUnsupportedError: if the response fails to indicate support
for "bytes" ranges."""
self._request_count += 1
head = self._session.head(
Expand All @@ -411,7 +411,7 @@ def _content_length_from_head(self) -> int:
assert head.status_code == codes.ok
accepted_range = head.headers.get("Accept-Ranges", None)
if accepted_range != "bytes":
raise HTTPRangeRequestUnsupported(
raise HTTPRangeRequestUnsupportedError(
f"server does not support byte ranges: header was '{accepted_range}'"
)
return int(head.headers["Content-Length"])
Expand All @@ -431,7 +431,7 @@ def _stream_response(self, start: int, end: int) -> Response:
response = self._session.get(self._url, headers=headers, stream=True)
response.raise_for_status()
if int(response.headers["Content-Length"]) != (end - start + 1):
raise HTTPRangeRequestNotRespected(
raise HTTPRangeRequestNotRespectedError(
f"server did not respect byte range request: "
f"requested {end - start + 1} bytes, got "
f"{response.headers['Content-Length']} bytes"
Expand Down Expand Up @@ -584,7 +584,9 @@ def _parse_full_length_from_content_range(arg: str) -> int:
"""
m = re.match(r"bytes [^/]+/([0-9]+)", arg)
if m is None:
raise HTTPRangeRequestUnsupported(f"could not parse Content-Range: '{arg}'")
raise HTTPRangeRequestUnsupportedError(
f"could not parse Content-Range: '{arg}'"
)
return int(m.group(1))

def _try_initial_chunk_request(
Expand Down Expand Up @@ -614,7 +616,7 @@ def _try_initial_chunk_request(
if accept_ranges == "bytes" and content_length <= initial_chunk_size:
return content_length, tail

raise HTTPRangeRequestUnsupported(
raise HTTPRangeRequestUnsupportedError(
f"did not receive partial content: got code {code}"
)

Expand Down Expand Up @@ -716,7 +718,7 @@ def _prefetch_metadata(self, name: str) -> str:
end = info.header_offset
break
if start is None:
raise UnsupportedWheel(
raise UnsupportedWheelError(
f"no {self._metadata_regex!r} found for {name} in {self.name}"
)
# If it is the last entry of the zip, then give us everything
Expand Down
50 changes: 25 additions & 25 deletions src/poetry/mixology/failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

from poetry.core.constraints.version import parse_constraint

from poetry.mixology.incompatibility_cause import ConflictCause
from poetry.mixology.incompatibility_cause import PythonCause
from poetry.mixology.incompatibility_cause import ConflictCauseError
from poetry.mixology.incompatibility_cause import PythonCauseError


if TYPE_CHECKING:
from poetry.mixology.incompatibility import Incompatibility


class SolveFailure(Exception):
class SolveFailureError(Exception):
def __init__(self, incompatibility: Incompatibility) -> None:
self._incompatibility = incompatibility

Expand All @@ -38,7 +38,7 @@ def write(self) -> str:
version_solutions = []
required_python_version_notification = False
for incompatibility in self._root.external_incompatibilities:
if isinstance(incompatibility.cause, PythonCause):
if isinstance(incompatibility.cause, PythonCauseError):
root_constraint = parse_constraint(
incompatibility.cause.root_python_version
)
Expand Down Expand Up @@ -73,7 +73,7 @@ def write(self) -> str:
if required_python_version_notification:
buffer.append("")

if isinstance(self._root.cause, ConflictCause):
if isinstance(self._root.cause, ConflictCauseError):
self._visit(self._root)
else:
self._write(self._root, f"Because {self._root}, version solving failed.")
Expand Down Expand Up @@ -150,10 +150,10 @@ def _visit(
incompatibility_string = str(incompatibility)

cause = incompatibility.cause
assert isinstance(cause, ConflictCause)
assert isinstance(cause, ConflictCauseError)

if isinstance(cause.conflict.cause, ConflictCause) and isinstance(
cause.other.cause, ConflictCause
if isinstance(cause.conflict.cause, ConflictCauseError) and isinstance(
cause.other.cause, ConflictCauseError
):
conflict_line = self._line_numbers.get(cause.conflict)
other_line = self._line_numbers.get(cause.other)
Expand Down Expand Up @@ -211,17 +211,17 @@ def _visit(
f" {incompatibility_string}",
numbered=numbered,
)
elif isinstance(cause.conflict.cause, ConflictCause) or isinstance(
cause.other.cause, ConflictCause
elif isinstance(cause.conflict.cause, ConflictCauseError) or isinstance(
cause.other.cause, ConflictCauseError
):
derived = (
cause.conflict
if isinstance(cause.conflict.cause, ConflictCause)
if isinstance(cause.conflict.cause, ConflictCauseError)
else cause.other
)
ext = (
cause.other
if isinstance(cause.conflict.cause, ConflictCause)
if isinstance(cause.conflict.cause, ConflictCauseError)
else cause.conflict
)

Expand All @@ -235,8 +235,8 @@ def _visit(
)
elif self._is_collapsible(derived):
derived_cause = derived.cause
assert isinstance(derived_cause, ConflictCause)
if isinstance(derived_cause.conflict.cause, ConflictCause):
assert isinstance(derived_cause, ConflictCauseError)
if isinstance(derived_cause.conflict.cause, ConflictCauseError):
collapsed_derived = derived_cause.conflict
collapsed_ext = derived_cause.other
else:
Expand Down Expand Up @@ -271,36 +271,36 @@ def _is_collapsible(self, incompatibility: Incompatibility) -> bool:
return False

cause = incompatibility.cause
assert isinstance(cause, ConflictCause)
if isinstance(cause.conflict.cause, ConflictCause) and isinstance(
cause.other.cause, ConflictCause
assert isinstance(cause, ConflictCauseError)
if isinstance(cause.conflict.cause, ConflictCauseError) and isinstance(
cause.other.cause, ConflictCauseError
):
return False

if not isinstance(cause.conflict.cause, ConflictCause) and not isinstance(
cause.other.cause, ConflictCause
if not isinstance(cause.conflict.cause, ConflictCauseError) and not isinstance(
cause.other.cause, ConflictCauseError
):
return False

complex = (
cause.conflict
if isinstance(cause.conflict.cause, ConflictCause)
if isinstance(cause.conflict.cause, ConflictCauseError)
else cause.other
)

return complex not in self._line_numbers

def _is_single_line(self, cause: ConflictCause) -> bool:
return not isinstance(cause.conflict.cause, ConflictCause) and not isinstance(
cause.other.cause, ConflictCause
)
def _is_single_line(self, cause: ConflictCauseError) -> bool:
return not isinstance(
cause.conflict.cause, ConflictCauseError
) and not isinstance(cause.other.cause, ConflictCauseError)

def _count_derivations(self, incompatibility: Incompatibility) -> None:
if incompatibility in self._derivations:
self._derivations[incompatibility] += 1
else:
self._derivations[incompatibility] = 1
cause = incompatibility.cause
if isinstance(cause, ConflictCause):
if isinstance(cause, ConflictCauseError):
self._count_derivations(cause.conflict)
self._count_derivations(cause.other)
Loading

0 comments on commit ab2f5a2

Please sign in to comment.