Skip to content

Commit b554820

Browse files
committed
Fix CI: type TupleManager.__init__ precisely instead of Any
ruff's ANN401 rule (enabled repo-wide) disallows a bare `Any` annotation on *args/**kwargs, which failed every CI build. Replace the *args/**kwargs signature with the actual accepted shape -- a single Mapping[str, T] or Iterable[tuple[str, T]] positional argument, defaulting to () to match dict()'s no-arg behavior, plus **kwargs: T -- which also lets mypy check the guard logic against a real type instead of Any.
1 parent e830d3d commit b554820

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

nameparser/config/__init__.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -284,41 +284,41 @@ class TupleManager(dict[str, T]):
284284
1.3.0 these constants were tuples of pairs.
285285
'''
286286

287-
def __init__(self, *args: Any, **kwargs: Any) -> None:
287+
def __init__(
288+
self,
289+
arg: Mapping[str, T] | Iterable[tuple[str, T]] = (),
290+
**kwargs: T,
291+
) -> None:
288292
# dict.__init__ accepts a bare str/bytes as an iterable-of-pairs
289293
# argument (each character iterates further, and dict() only
290294
# complains once it hits a "pair" of the wrong length) and accepts an
291295
# iterable of 2-character strings as if each one were a (key, value)
292296
# pair, silently shredding it -- mirrors SetManager's guard against
293297
# the same class of mistake (#238), applied to the mapping
294298
# constructor's own failure modes (#242).
295-
if args:
296-
arg = args[0]
297-
if isinstance(arg, bytes):
298-
raise TypeError(
299-
"expected a mapping or iterable of (key, value) pairs, got a "
300-
f"single bytes; decode it first: [{arg!r}.decode()]"
301-
)
302-
if isinstance(arg, str):
303-
raise TypeError(
304-
"expected a mapping or iterable of (key, value) pairs, got a "
305-
f"single str; wrap it in a list: [{arg!r}]"
306-
)
307-
if not isinstance(arg, Mapping):
308-
checked = []
309-
for item in arg:
310-
if isinstance(item, (str, bytes)):
311-
raise TypeError(
312-
"expected (key, value) pairs, got a "
313-
f"{'bytes' if isinstance(item, bytes) else 'str'} "
314-
f"element {item!r}; a 2-character string silently "
315-
"splits into a key and a value"
316-
)
317-
checked.append(item)
318-
arg = checked
319-
super().__init__(arg, **kwargs)
320-
else:
321-
super().__init__(**kwargs)
299+
if isinstance(arg, bytes):
300+
raise TypeError(
301+
"expected a mapping or iterable of (key, value) pairs, got a "
302+
f"single bytes; decode it first: [{arg!r}.decode()]"
303+
)
304+
if isinstance(arg, str):
305+
raise TypeError(
306+
"expected a mapping or iterable of (key, value) pairs, got a "
307+
f"single str; wrap it in a list: [{arg!r}]"
308+
)
309+
if not isinstance(arg, Mapping):
310+
checked = []
311+
for item in arg:
312+
if isinstance(item, (str, bytes)):
313+
raise TypeError(
314+
"expected (key, value) pairs, got a "
315+
f"{'bytes' if isinstance(item, bytes) else 'str'} "
316+
f"element {item!r}; a 2-character string silently "
317+
"splits into a key and a value"
318+
)
319+
checked.append(item)
320+
arg = checked
321+
super().__init__(arg, **kwargs)
322322

323323
def __getattr__(self, attr: str) -> T | None:
324324
# Otherwise the dict default (None) is mistaken for a real protocol hook.

0 commit comments

Comments
 (0)