Skip to content

Commit 5ab8ae9

Browse files
committed
pylock: simplify
1 parent 2343f8a commit 5ab8ae9

File tree

2 files changed

+3
-23
lines changed

2 files changed

+3
-23
lines changed

src/packaging/pylock.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import logging
55
import re
66
import sys
7-
from collections.abc import Iterable, Mapping, Sequence
7+
from collections.abc import Mapping, Sequence
88
from dataclasses import dataclass
99
from datetime import datetime
1010
from pathlib import Path
@@ -218,16 +218,6 @@ def _get_required_list_of_objects(
218218
return result
219219

220220

221-
def _exactly_one(iterable: Iterable[object]) -> bool:
222-
found = False
223-
for item in iterable:
224-
if item:
225-
if found:
226-
return False
227-
found = True
228-
return found
229-
230-
231221
def _validate_path_url(path: str | None, url: str | None) -> None:
232222
if not path and not url:
233223
raise PylockValidationError("path or url must be provided")
@@ -522,14 +512,14 @@ def __init__(
522512
if not is_normalized_name(self.name):
523513
raise PylockValidationError(f"Package name {self.name!r} is not normalized")
524514
if self.sdist or self.wheels:
525-
if any([self.vcs, self.directory, self.archive]):
515+
if self.vcs or self.directory or self.archive:
526516
raise PylockValidationError(
527517
"None of vcs, directory, archive "
528518
"must be set if sdist or wheels are set"
529519
)
530520
else:
531521
# no sdist nor wheels
532-
if not _exactly_one([self.vcs, self.directory, self.archive]):
522+
if not (bool(self.vcs) ^ bool(self.directory) ^ bool(self.archive)):
533523
raise PylockValidationError(
534524
"Exactly one of vcs, directory, archive must be set "
535525
"if sdist and wheels are not set"

tests/test_pylock.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
PylockRequiredKeyError,
1919
PylockUnsupportedVersionError,
2020
PylockValidationError,
21-
_exactly_one,
2221
from_dict,
2322
is_valid_pylock_path,
2423
)
@@ -44,15 +43,6 @@ def test_pylock_file_name(file_name: str, valid: bool) -> None:
4443
assert is_valid_pylock_path(Path(file_name)) is valid
4544

4645

47-
def test_exactly_one() -> None:
48-
assert not _exactly_one([])
49-
assert not _exactly_one([False])
50-
assert not _exactly_one([False, False])
51-
assert not _exactly_one([True, True])
52-
assert _exactly_one([True])
53-
assert _exactly_one([True, False])
54-
55-
5646
# This is the PEP 751 example, with the following differences:
5747
# - a minor modification to the 'environments' field to use double quotes
5848
# instead of single quotes, since that is what 'packaging' does when

0 commit comments

Comments
 (0)