-
-
Notifications
You must be signed in to change notification settings - Fork 50
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
Check types after overwriting #31
Comments
You are right. This should not fail. |
@mpariente after a fast look at this I think that the fix is not simple. It seems I would need to reimplement argparse's For the time being, the workaround is to not include the invalid entries in the config file. It is a bit cumbersome because |
- Fixed instantiate_classes failing for type hints with nargs='+'. - Useful error message when init_args value invalid. - Specific error message when subclass dict has unexpected keys. - mock_module for nicer tests related to class paths.
Finally figured out a way to make this work. Fixed in c5119c6. |
I've been getting a possibly related issue related to pytorch lightning's CLI when checking types of callbacks. Here is a minimal example:
When providing a invalid callback path, the normal mode correctly raises an error: usage: cli.py [-h] [-c CONFIG] [--print_config [={comments,skip_null,skip_default}+]] {fit,validate,test,predict,tune} ...
cli.py: error: Configuration check failed :: Parser key "trainer.callbacks": Value "NotARealCallback" does not validate against any of the types in typing.Union[typing.List[pytorch_lightning.callbacks.callback.Callback], pytorch_lightning.callbacks.callback.Callback, NoneType]:
- Expected a List but got "NotARealCallback"
- Expected a dot import path string: NotARealCallback
- Expected a <class 'NoneType'> but got "NotARealCallback" However, when using the
It's not a huge problem, since the type will be checked as soon as the config is instantiated, but it's still a bit surprising! |
@glothe thanks for the input. I am also concerned about the following: from jsonargparse import ActionConfigFile, ArgumentParser
from typing import List
parser = ArgumentParser()
parser.add_argument('--cfg', action=ActionConfigFile)
parser.add_argument('--val', type=List[int])
print(parser.parse_args(['--val=2', '--cfg=val+: [3, 4]', '--val+=5'])) The parsing correctly gets the value as |
- No failures when intermediate arguments miss required arguments. - Parsing error when intermediate arguments have an invalid value.
The original description above suggested to only validate at the end, giving as example required arguments. I think the required arguments is the only case in which it should be checked at the end. Any intermediate argument which provides an invalid value should make the parser fail, even for |
- No failures when intermediate arguments miss required arguments. - Parsing error when intermediate arguments have an invalid value.
The problem
If the value is wrongly typed in the config file (for example if a non-optional positional arg was not specified with
--print_config
), and is being overwritten by a valid value, an error is raised nonetheless.What I'd like
Check types after all the parsing has been done, to allow this use case.
Minimal example
Way that works
Way that doesn't
and this is the error message:
The text was updated successfully, but these errors were encountered: