Skip to content

Commit

Permalink
Fixed str type fails to parse value when pyyaml raises ConstructorError
Browse files Browse the repository at this point in the history
  • Loading branch information
mauvilsa committed Nov 8, 2022
1 parent e9b8690 commit 72672b4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ The semantic versioning only considers the public API as described in
paths are considered internals and can change in minor and patch releases.


v4.16.1 (2022-11-??)
--------------------

Fixed
^^^^^
- ``str`` type fails to parse value when pyyaml raises ``ConstructorError``
`#189 <https://github.com/omni-us/jsonargparse/issues/189>`__.


v4.16.0 (2022-10-28)
--------------------

Expand Down
2 changes: 1 addition & 1 deletion jsonargparse/loaders_dumpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def jsonnet_load(stream, path='', ext_vars=None):
'jsonnet': jsonnet_load,
}

pyyaml_exceptions = (yaml.parser.ParserError, yaml.scanner.ScannerError)
pyyaml_exceptions = (yaml.YAMLError,)
jsonnet_exceptions = pyyaml_exceptions + (ValueError,)

loader_exceptions: Dict[str, Tuple[Type[Exception], ...]] = {
Expand Down
6 changes: 6 additions & 0 deletions jsonargparse_tests/test_typehints.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ def __init__(self, val: str = '-'):
self.assertEqual(value, parser.parse_args([f'--cls.val={value}']).cls.init_args.val)


def test_str_with_yaml_constructor_error(self):
parser = ArgumentParser()
parser.add_argument('--val', type=str)
self.assertEqual('{{something}}', parser.parse_args(['--val={{something}}']).val)


def test_list(self):
for list_type in [Iterable, List, Sequence]:
with self.subTest(str(list_type)):
Expand Down

0 comments on commit 72672b4

Please sign in to comment.