Skip to content

Commit 6f59db8

Browse files
committed
[stubs](chore) Add safety check
1 parent f4f70b5 commit 6f59db8

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pydentification/stubs.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ def cast_to_path(func: Callable):
99
"""
1010
Decorator to cast string arguments to Path in the function signature.
1111
Uses type hints to determine which arguments should be cast.
12+
13+
:note: do not use with functions that have missing type hints
1214
"""
15+
1316
def cast(arg: Any, hint: Any) -> Any:
1417
if hint == Union[str, Path]:
1518
return Path(arg)
@@ -21,6 +24,9 @@ def wrapper(*args, **kwargs):
2124
new_args = []
2225
new_kwargs = {}
2326

27+
if len(args) + len(kwargs) > len(hints):
28+
raise TypeError("Some arguments are missing type hints!")
29+
2430
for arg, (name, hint) in zip(args, hints.items()):
2531
new_args.append(cast(arg, hint))
2632
for name, arg in kwargs.items():

0 commit comments

Comments
 (0)