Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config check failed with add_subclass_arguments(required=False) #83

Closed
carmocca opened this issue Aug 19, 2021 · 3 comments · Fixed by #90
Closed

Config check failed with add_subclass_arguments(required=False) #83

carmocca opened this issue Aug 19, 2021 · 3 comments · Fixed by #90
Labels
bug Something isn't working

Comments

@carmocca
Copy link
Contributor

carmocca commented Aug 19, 2021

from jsonargparse import ArgumentParser

class A:
    ...

class B:
    ...

parser = ArgumentParser()
parser.add_subclass_arguments((A, B), nested_key="foo", required=False)
args = parser.parse_args()

produces:

scratch_12.py: error: Configuration check failed :: Parser key "foo": Value {} does not validate against any of the types in typing.Union[__main__.A, __main__.B]:
  - Type <class '__main__.A'> expects an str or a Dict with a class_path entry but got "{}"
  - Type <class '__main__.B'> expects an str or a Dict with a class_path entry but got "{}"

My assumption was that by setting required=False, --foo does not need to be passed.
And args would be an empty dictionary.

@mauvilsa mauvilsa added the bug Something isn't working label Aug 26, 2021
@mauvilsa
Copy link
Member

mauvilsa commented Sep 9, 2021

Fixed in v3.19.2

@mauvilsa mauvilsa closed this as completed Sep 9, 2021
@carmocca
Copy link
Contributor Author

@mauvilsa If I add the following line at the end of the snippet above, the error still appears:

args_init = parser.instantiate_classes(args)

Can you re-open this?

@mauvilsa mauvilsa reopened this Sep 15, 2021
@carmocca
Copy link
Contributor Author

Looking at the commit that closed this PR, I'd say that the assertion should be changed to self.assertEqual(cfg, {})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants