Skip to content

Commit 80f3f5e

Browse files
committed
Rename exceptions to have Error suffix
1 parent 150ff09 commit 80f3f5e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+191
-189
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ extend-select = [
126126
ignore = [
127127
"B904", # use 'raise ... from err'
128128
"B905", # use explicit 'strict=' parameter with 'zip()'
129-
"N818", # Exception name should be named with an Error suffix
130129
]
131130
extend-safe-fixes = [
132131
"TCH", # move import from and to TYPE_CHECKING blocks

src/poetry/console/commands/group_command.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from poetry.core.packages.dependency_group import MAIN_GROUP
88

99
from poetry.console.commands.command import Command
10-
from poetry.console.exceptions import GroupNotFound
10+
from poetry.console.exceptions import GroupNotFoundError
1111

1212

1313
if TYPE_CHECKING:
@@ -128,4 +128,4 @@ def _validate_group_options(self, group_options: dict[str, set[str]]) -> None:
128128
for opt in sorted(invalid_options[group])
129129
)
130130
message_parts.append(f"{group} (via {opts})")
131-
raise GroupNotFound(f"Group(s) not found: {', '.join(message_parts)}")
131+
raise GroupNotFoundError(f"Group(s) not found: {', '.join(message_parts)}")

src/poetry/console/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ class PoetryConsoleError(CleoError):
77
pass
88

99

10-
class GroupNotFound(PoetryConsoleError):
10+
class GroupNotFoundError(PoetryConsoleError):
1111
pass

src/poetry/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import annotations
22

33

4-
class PoetryException(Exception):
4+
class PoetryError(Exception):
55
pass

src/poetry/factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from poetry.core.packages.dependency_group import MAIN_GROUP
1515

1616
from poetry.config.config import Config
17-
from poetry.exceptions import PoetryException
17+
from poetry.exceptions import PoetryError
1818
from poetry.json import validate_object
1919
from poetry.packages.locker import Locker
2020
from poetry.plugins.plugin import Plugin
@@ -155,7 +155,7 @@ def create_pool(
155155
)
156156

157157
if not pool.repositories:
158-
raise PoetryException(
158+
raise PoetryError(
159159
"At least one source must not be configured as 'explicit'."
160160
)
161161

src/poetry/inspection/lazy_wheel.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@ class LazyWheelUnsupportedError(Exception):
4545
"""Raised when a lazy wheel is unsupported."""
4646

4747

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

5151

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

5656

57-
class UnsupportedWheel(LazyWheelUnsupportedError):
57+
class UnsupportedWheelError(LazyWheelUnsupportedError):
5858
"""Unsupported wheel."""
5959

6060

61-
class InvalidWheel(LazyWheelUnsupportedError):
61+
class InvalidWheelError(LazyWheelUnsupportedError):
6262
"""Invalid (e.g. corrupt) wheel."""
6363

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

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

293293
def __init__(
294294
self,
@@ -401,7 +401,7 @@ def _reset_content(self) -> None:
401401
def _content_length_from_head(self) -> int:
402402
"""Performs a HEAD request to extract the Content-Length.
403403
404-
:raises HTTPRangeRequestUnsupported: if the response fails to indicate support
404+
:raises HTTPRangeRequestUnsupportedError: if the response fails to indicate support
405405
for "bytes" ranges."""
406406
self._request_count += 1
407407
head = self._session.head(
@@ -411,7 +411,7 @@ def _content_length_from_head(self) -> int:
411411
assert head.status_code == codes.ok
412412
accepted_range = head.headers.get("Accept-Ranges", None)
413413
if accepted_range != "bytes":
414-
raise HTTPRangeRequestUnsupported(
414+
raise HTTPRangeRequestUnsupportedError(
415415
f"server does not support byte ranges: header was '{accepted_range}'"
416416
)
417417
return int(head.headers["Content-Length"])
@@ -431,7 +431,7 @@ def _stream_response(self, start: int, end: int) -> Response:
431431
response = self._session.get(self._url, headers=headers, stream=True)
432432
response.raise_for_status()
433433
if int(response.headers["Content-Length"]) != (end - start + 1):
434-
raise HTTPRangeRequestNotRespected(
434+
raise HTTPRangeRequestNotRespectedError(
435435
f"server did not respect byte range request: "
436436
f"requested {end - start + 1} bytes, got "
437437
f"{response.headers['Content-Length']} bytes"
@@ -584,7 +584,9 @@ def _parse_full_length_from_content_range(arg: str) -> int:
584584
"""
585585
m = re.match(r"bytes [^/]+/([0-9]+)", arg)
586586
if m is None:
587-
raise HTTPRangeRequestUnsupported(f"could not parse Content-Range: '{arg}'")
587+
raise HTTPRangeRequestUnsupportedError(
588+
f"could not parse Content-Range: '{arg}'"
589+
)
588590
return int(m.group(1))
589591

590592
def _try_initial_chunk_request(
@@ -614,7 +616,7 @@ def _try_initial_chunk_request(
614616
if accept_ranges == "bytes" and content_length <= initial_chunk_size:
615617
return content_length, tail
616618

617-
raise HTTPRangeRequestUnsupported(
619+
raise HTTPRangeRequestUnsupportedError(
618620
f"did not receive partial content: got code {code}"
619621
)
620622

@@ -716,7 +718,7 @@ def _prefetch_metadata(self, name: str) -> str:
716718
end = info.header_offset
717719
break
718720
if start is None:
719-
raise UnsupportedWheel(
721+
raise UnsupportedWheelError(
720722
f"no {self._metadata_regex!r} found for {name} in {self.name}"
721723
)
722724
# If it is the last entry of the zip, then give us everything

src/poetry/mixology/failure.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
from poetry.core.constraints.version import parse_constraint
66

7-
from poetry.mixology.incompatibility_cause import ConflictCause
8-
from poetry.mixology.incompatibility_cause import PythonCause
7+
from poetry.mixology.incompatibility_cause import ConflictCauseError
8+
from poetry.mixology.incompatibility_cause import PythonCauseError
99

1010

1111
if TYPE_CHECKING:
1212
from poetry.mixology.incompatibility import Incompatibility
1313

1414

15-
class SolveFailure(Exception):
15+
class SolveFailureError(Exception):
1616
def __init__(self, incompatibility: Incompatibility) -> None:
1717
self._incompatibility = incompatibility
1818

@@ -38,7 +38,7 @@ def write(self) -> str:
3838
version_solutions = []
3939
required_python_version_notification = False
4040
for incompatibility in self._root.external_incompatibilities:
41-
if isinstance(incompatibility.cause, PythonCause):
41+
if isinstance(incompatibility.cause, PythonCauseError):
4242
root_constraint = parse_constraint(
4343
incompatibility.cause.root_python_version
4444
)
@@ -73,7 +73,7 @@ def write(self) -> str:
7373
if required_python_version_notification:
7474
buffer.append("")
7575

76-
if isinstance(self._root.cause, ConflictCause):
76+
if isinstance(self._root.cause, ConflictCauseError):
7777
self._visit(self._root)
7878
else:
7979
self._write(self._root, f"Because {self._root}, version solving failed.")
@@ -150,10 +150,10 @@ def _visit(
150150
incompatibility_string = str(incompatibility)
151151

152152
cause = incompatibility.cause
153-
assert isinstance(cause, ConflictCause)
153+
assert isinstance(cause, ConflictCauseError)
154154

155-
if isinstance(cause.conflict.cause, ConflictCause) and isinstance(
156-
cause.other.cause, ConflictCause
155+
if isinstance(cause.conflict.cause, ConflictCauseError) and isinstance(
156+
cause.other.cause, ConflictCauseError
157157
):
158158
conflict_line = self._line_numbers.get(cause.conflict)
159159
other_line = self._line_numbers.get(cause.other)
@@ -211,17 +211,17 @@ def _visit(
211211
f" {incompatibility_string}",
212212
numbered=numbered,
213213
)
214-
elif isinstance(cause.conflict.cause, ConflictCause) or isinstance(
215-
cause.other.cause, ConflictCause
214+
elif isinstance(cause.conflict.cause, ConflictCauseError) or isinstance(
215+
cause.other.cause, ConflictCauseError
216216
):
217217
derived = (
218218
cause.conflict
219-
if isinstance(cause.conflict.cause, ConflictCause)
219+
if isinstance(cause.conflict.cause, ConflictCauseError)
220220
else cause.other
221221
)
222222
ext = (
223223
cause.other
224-
if isinstance(cause.conflict.cause, ConflictCause)
224+
if isinstance(cause.conflict.cause, ConflictCauseError)
225225
else cause.conflict
226226
)
227227

@@ -235,8 +235,8 @@ def _visit(
235235
)
236236
elif self._is_collapsible(derived):
237237
derived_cause = derived.cause
238-
assert isinstance(derived_cause, ConflictCause)
239-
if isinstance(derived_cause.conflict.cause, ConflictCause):
238+
assert isinstance(derived_cause, ConflictCauseError)
239+
if isinstance(derived_cause.conflict.cause, ConflictCauseError):
240240
collapsed_derived = derived_cause.conflict
241241
collapsed_ext = derived_cause.other
242242
else:
@@ -271,36 +271,36 @@ def _is_collapsible(self, incompatibility: Incompatibility) -> bool:
271271
return False
272272

273273
cause = incompatibility.cause
274-
assert isinstance(cause, ConflictCause)
275-
if isinstance(cause.conflict.cause, ConflictCause) and isinstance(
276-
cause.other.cause, ConflictCause
274+
assert isinstance(cause, ConflictCauseError)
275+
if isinstance(cause.conflict.cause, ConflictCauseError) and isinstance(
276+
cause.other.cause, ConflictCauseError
277277
):
278278
return False
279279

280-
if not isinstance(cause.conflict.cause, ConflictCause) and not isinstance(
281-
cause.other.cause, ConflictCause
280+
if not isinstance(cause.conflict.cause, ConflictCauseError) and not isinstance(
281+
cause.other.cause, ConflictCauseError
282282
):
283283
return False
284284

285285
complex = (
286286
cause.conflict
287-
if isinstance(cause.conflict.cause, ConflictCause)
287+
if isinstance(cause.conflict.cause, ConflictCauseError)
288288
else cause.other
289289
)
290290

291291
return complex not in self._line_numbers
292292

293-
def _is_single_line(self, cause: ConflictCause) -> bool:
294-
return not isinstance(cause.conflict.cause, ConflictCause) and not isinstance(
295-
cause.other.cause, ConflictCause
296-
)
293+
def _is_single_line(self, cause: ConflictCauseError) -> bool:
294+
return not isinstance(
295+
cause.conflict.cause, ConflictCauseError
296+
) and not isinstance(cause.other.cause, ConflictCauseError)
297297

298298
def _count_derivations(self, incompatibility: Incompatibility) -> None:
299299
if incompatibility in self._derivations:
300300
self._derivations[incompatibility] += 1
301301
else:
302302
self._derivations[incompatibility] = 1
303303
cause = incompatibility.cause
304-
if isinstance(cause, ConflictCause):
304+
if isinstance(cause, ConflictCauseError):
305305
self._count_derivations(cause.conflict)
306306
self._count_derivations(cause.other)

0 commit comments

Comments
 (0)