Skip to content

Commit 55c3aeb

Browse files
committed
pylock: make more module level stuff "private"
1 parent b9f0a7b commit 55c3aeb

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

src/packaging/pylock.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@
4141
"is_valid_pylock_path",
4242
]
4343

44-
T = TypeVar("T")
45-
T2 = TypeVar("T2")
44+
_T = TypeVar("_T")
45+
_T2 = TypeVar("_T2")
4646

4747

48-
class FromMappingProtocol(Protocol): # pragma: no cover
48+
class _FromMappingProtocol(Protocol): # pragma: no cover
4949
@classmethod
5050
def _from_dict(cls, d: Mapping[str, Any]) -> Self: ...
5151

5252

53-
FromMappingProtocolT = TypeVar("FromMappingProtocolT", bound=FromMappingProtocol)
53+
_FromMappingProtocolT = TypeVar("_FromMappingProtocolT", bound=_FromMappingProtocol)
5454

5555

56-
PYLOCK_FILE_NAME_RE = re.compile(r"^pylock\.([^.]+)\.toml$")
56+
_PYLOCK_FILE_NAME_RE = re.compile(r"^pylock\.([^.]+)\.toml$")
5757

5858

5959
def is_valid_pylock_path(path: Path) -> bool:
60-
return path.name == "pylock.toml" or bool(PYLOCK_FILE_NAME_RE.match(path.name))
60+
return path.name == "pylock.toml" or bool(_PYLOCK_FILE_NAME_RE.match(path.name))
6161

6262

6363
def _str_to_normalized_name(name: str) -> NormalizedName:
@@ -87,7 +87,7 @@ def _toml_dict_factory(data: list[tuple[str, Any]]) -> dict[str, Any]:
8787
}
8888

8989

90-
def _get(d: Mapping[str, Any], expected_type: type[T], key: str) -> T | None:
90+
def _get(d: Mapping[str, Any], expected_type: type[_T], key: str) -> _T | None:
9191
"""Get a value from the dictionary and verify it's the expected type."""
9292
if (value := d.get(key)) is None:
9393
return None
@@ -100,16 +100,16 @@ def _get(d: Mapping[str, Any], expected_type: type[T], key: str) -> T | None:
100100
return value
101101

102102

103-
def _get_required(d: Mapping[str, Any], expected_type: type[T], key: str) -> T:
103+
def _get_required(d: Mapping[str, Any], expected_type: type[_T], key: str) -> _T:
104104
"""Get a required value from the dictionary and verify it's the expected type."""
105105
if (value := _get(d, expected_type, key)) is None:
106106
raise PylockRequiredKeyError(key)
107107
return value
108108

109109

110110
def _get_sequence(
111-
d: Mapping[str, Any], expected_item_type: type[T], key: str
112-
) -> Sequence[T] | None:
111+
d: Mapping[str, Any], expected_item_type: type[_T], key: str
112+
) -> Sequence[_T] | None:
113113
"""Get a list value from the dictionary and verify it's the expected items type."""
114114
value = _get(d, Sequence, key) # type: ignore[type-abstract]
115115
if value is None:
@@ -126,10 +126,10 @@ def _get_sequence(
126126

127127
def _get_as(
128128
d: Mapping[str, Any],
129-
expected_type: type[T],
130-
target_type: Callable[[T], T2],
129+
expected_type: type[_T],
130+
target_type: Callable[[_T], _T2],
131131
key: str,
132-
) -> T2 | None:
132+
) -> _T2 | None:
133133
"""Get a value from the dictionary, verify it's the expected type,
134134
and convert to the target type.
135135
@@ -145,10 +145,10 @@ def _get_as(
145145

146146
def _get_required_as(
147147
d: Mapping[str, Any],
148-
expected_type: type[T],
149-
target_type: Callable[[T], T2],
148+
expected_type: type[_T],
149+
target_type: Callable[[_T], _T2],
150150
key: str,
151-
) -> T2:
151+
) -> _T2:
152152
"""Get a required value from the dict, verify it's the expected type,
153153
and convert to the target type."""
154154
if (value := _get_as(d, expected_type, target_type, key)) is None:
@@ -158,10 +158,10 @@ def _get_required_as(
158158

159159
def _get_sequence_as(
160160
d: Mapping[str, Any],
161-
expected_item_type: type[T],
162-
target_item_type: Callable[[T], T2],
161+
expected_item_type: type[_T],
162+
target_item_type: Callable[[_T], _T2],
163163
key: str,
164-
) -> Sequence[T2] | None:
164+
) -> Sequence[_T2] | None:
165165
"""Get list value from dictionary and verify expected items type."""
166166
if (value := _get_sequence(d, expected_item_type, key)) is None:
167167
return None
@@ -177,8 +177,8 @@ def _get_sequence_as(
177177

178178

179179
def _get_object(
180-
d: Mapping[str, Any], target_type: type[FromMappingProtocolT], key: str
181-
) -> FromMappingProtocolT | None:
180+
d: Mapping[str, Any], target_type: type[_FromMappingProtocolT], key: str
181+
) -> _FromMappingProtocolT | None:
182182
"""Get a dictionary value from the dictionary and convert it to a dataclass."""
183183
value = _get(d, Mapping, key) # type: ignore[type-abstract]
184184
if value is None:
@@ -190,8 +190,8 @@ def _get_object(
190190

191191

192192
def _get_sequence_of_objects(
193-
d: Mapping[str, Any], target_item_type: type[FromMappingProtocolT], key: str
194-
) -> Sequence[FromMappingProtocolT] | None:
193+
d: Mapping[str, Any], target_item_type: type[_FromMappingProtocolT], key: str
194+
) -> Sequence[_FromMappingProtocolT] | None:
195195
"""Get a list value from the dictionary and convert its items to a dataclass."""
196196
value = _get(d, Sequence, key) # type: ignore[type-abstract]
197197
if value is None:
@@ -213,8 +213,8 @@ def _get_sequence_of_objects(
213213

214214

215215
def _get_required_list_of_objects(
216-
d: Mapping[str, Any], target_type: type[FromMappingProtocolT], key: str
217-
) -> Sequence[FromMappingProtocolT]:
216+
d: Mapping[str, Any], target_type: type[_FromMappingProtocolT], key: str
217+
) -> Sequence[_FromMappingProtocolT]:
218218
"""Get a required list value from the dictionary and convert its items to a
219219
dataclass."""
220220
if (result := _get_sequence_of_objects(d, target_type, key)) is None:

0 commit comments

Comments
 (0)