Skip to content

Commit 394ed84

Browse files
committed
pylock: make internal exception class private
This was not meant to be public
1 parent 686d204 commit 394ed84

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/packaging/pylock.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def _get(d: Mapping[str, Any], expected_type: type[_T], key: str) -> _T | None:
9696
def _get_required(d: Mapping[str, Any], expected_type: type[_T], key: str) -> _T:
9797
"""Get a required value from the dictionary and verify it's the expected type."""
9898
if (value := _get(d, expected_type, key)) is None:
99-
raise PylockRequiredKeyError(key)
99+
raise _PylockRequiredKeyError(key)
100100
return value
101101

102102

@@ -150,7 +150,7 @@ def _get_required_as(
150150
"""Get a required value from the dict, verify it's the expected type,
151151
and convert to the target type."""
152152
if (value := _get_as(d, expected_type, target_type, key)) is None:
153-
raise PylockRequiredKeyError(key)
153+
raise _PylockRequiredKeyError(key)
154154
return value
155155

156156

@@ -209,7 +209,7 @@ def _get_required_sequence_of_objects(
209209
"""Get a required list value from the dictionary and convert its items to a
210210
dataclass."""
211211
if (result := _get_sequence_of_objects(d, target_item_type, key)) is None:
212-
raise PylockRequiredKeyError(key)
212+
raise _PylockRequiredKeyError(key)
213213
return result
214214

215215

@@ -263,7 +263,7 @@ def __str__(self) -> str:
263263
return self.message
264264

265265

266-
class PylockRequiredKeyError(PylockValidationError):
266+
class _PylockRequiredKeyError(PylockValidationError):
267267
def __init__(self, key: str) -> None:
268268
super().__init__("Missing required value", context=key)
269269

tests/test_pylock.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
PackageVcs,
1616
PackageWheel,
1717
Pylock,
18-
PylockRequiredKeyError,
1918
PylockUnsupportedVersionError,
2019
PylockValidationError,
2120
is_valid_pylock_path,
@@ -104,7 +103,7 @@ def test_pylock_missing_version() -> None:
104103
"created-by": "pip",
105104
"packages": [],
106105
}
107-
with pytest.raises(PylockRequiredKeyError) as exc_info:
106+
with pytest.raises(PylockValidationError) as exc_info:
108107
Pylock.from_dict(data)
109108
assert str(exc_info.value) == "Missing required value in 'lock-version'"
110109

@@ -114,7 +113,7 @@ def test_pylock_missing_created_by() -> None:
114113
"lock-version": "1.0",
115114
"packages": [],
116115
}
117-
with pytest.raises(PylockRequiredKeyError) as exc_info:
116+
with pytest.raises(PylockValidationError) as exc_info:
118117
Pylock.from_dict(data)
119118
assert str(exc_info.value) == "Missing required value in 'created-by'"
120119

@@ -124,7 +123,7 @@ def test_pylock_missing_packages() -> None:
124123
"lock-version": "1.0",
125124
"created-by": "uv",
126125
}
127-
with pytest.raises(PylockRequiredKeyError) as exc_info:
126+
with pytest.raises(PylockValidationError) as exc_info:
128127
Pylock.from_dict(data)
129128
assert str(exc_info.value) == "Missing required value in 'packages'"
130129

0 commit comments

Comments
 (0)