diff --git a/simple_parsing/annotation_utils/get_field_annotations.py b/simple_parsing/annotation_utils/get_field_annotations.py index 8b44d0d7..e7849a6e 100644 --- a/simple_parsing/annotation_utils/get_field_annotations.py +++ b/simple_parsing/annotation_utils/get_field_annotations.py @@ -6,7 +6,7 @@ from contextlib import contextmanager from dataclasses import InitVar from logging import getLogger as get_logger -from typing import Any, Dict, Iterator, Optional, get_type_hints +from typing import Any, Dict, Iterator, Optional, get_type_hints, TypeVar logger = get_logger(__name__) @@ -18,6 +18,7 @@ "dict": typing.Dict, "list": typing.List, "type": typing.Type, + "D": TypeVar("D"), } diff --git a/test/test_issue_181.py b/test/test_issue_181.py new file mode 100644 index 00000000..e64ea07a --- /dev/null +++ b/test/test_issue_181.py @@ -0,0 +1,20 @@ +from __future__ import annotations +from simple_parsing import Serializable, ArgumentParser +from dataclasses import dataclass +import pytest + +@dataclass +class MyArguments(Serializable): + arg1: str = 'this_argment' + +@pytest.mark.parametrize( + 'sys_argv, result', [ + (['test.py'], 'this_argment'), + (['test.py', '--arg1', 'test2'], 'test2') + ], +) +def test_simple_parsing(sys_argv, result): + parser = ArgumentParser() + parser.add_arguments(MyArguments, 'myargs') + args, _ = parser.parse_known_args(sys_argv) + assert args.myargs.arg1 == result \ No newline at end of file