Skip to content

Commit

Permalink
modify forward_refs_to_types to fix issue 181 (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiruiluo authored Dec 6, 2022
1 parent 980ef6e commit c9cdd84
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion simple_parsing/annotation_utils/get_field_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -18,6 +18,7 @@
"dict": typing.Dict,
"list": typing.List,
"type": typing.Type,
"D": TypeVar("D"),
}


Expand Down
20 changes: 20 additions & 0 deletions test/test_issue_181.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c9cdd84

Please sign in to comment.