Skip to content

Commit ff5ef65

Browse files
authored
Merge pull request #33 from explosion/fix/type-stringification
prevent raw str leaking into ArgparseArg.type
2 parents 2fc2e6c + 61b9aaa commit ff5ef65

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

radicli/tests/test_util.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from uuid import UUID
66
import pytest
77
import shutil
8-
from radicli.util import stringify_type, get_list_converter
8+
from radicli.util import stringify_type, get_list_converter, get_arg, Arg
99

1010
_KindT = TypeVar("_KindT", bound=Union[str, int, float, Path])
1111

@@ -61,3 +61,13 @@ def test_stringify_type(arg_type, expected):
6161
def test_get_list_converter(item_type, value, expected):
6262
converter = get_list_converter(item_type)
6363
assert converter(value) == expected
64+
65+
def test_get_arg_string_type():
66+
arg_info = Arg()
67+
result = get_arg("test_param", arg_info, "str")
68+
assert result.type is str
69+
70+
def test_get_arg_regular_type():
71+
arg_info = Arg()
72+
result = get_arg("test_param", arg_info, int)
73+
assert result.type is int

radicli/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ def get_arg(
296296
skip_resolve: bool = False,
297297
) -> ArgparseArg:
298298
"""Generate an argument to add to argparse and interpret types if possible."""
299+
if isinstance(param_type, str):
300+
# Windows may pass param_types as str
301+
param_type = BASE_TYPES_MAP.get(param_type, None)
299302
arg = ArgparseArg(
300303
id=param,
301304
arg=orig_arg,

0 commit comments

Comments
 (0)