omni-us / jsonargparse

Implement minimal boilerplate CLIs derived from type hints and parse from command line, config files and environment variables
https://jsonargparse.readthedocs.io
MIT License
314 stars 42 forks source link

Raise an error on the latest Python 3.11.9 #484

Closed vinnamkim closed 4 months ago

vinnamkim commented 5 months ago

🐛 Bug report

Hi, thanks in advance for your hard work. Today, a CI pipeline of our repository started being broken only on Python 3.11: https://github.com/openvinotoolkit/training_extensions/actions/runs/8608284639/job/23590400567 This seems that Python 3.11.9 is released very recently (Apr. 8) and jsonargparse got affected by this update. Please see the following minimal reproduction Python script.

To reproduce

from jsonargparse import ActionConfigFile, ArgumentParser

class MyModel:
    def __init__(self, a: int, b: int):
        self.a = a
        self.b = b

parser = ArgumentParser()
parser.add_argument("--model", type=MyModel)
parser.add_argument("--config", action=ActionConfigFile)
cfg = parser.parse_args()

print(parser.instantiate_classes(cfg))
print(MyModel())
((.venv-3119) ) vinnamki@vinnamki:~/otx/training_extensions$ python test6.py --model=__main__.MyModel --model.a=1 --model.b=2

Traceback (most recent call last):
  File "/home/vinnamki/otx/training_extensions/test6.py", line 11, in <module>
    cfg = parser.parse_args()
          ^^^^^^^^^^^^^^^^^^^
  File "/home/vinnamki/otx/training_extensions/.venv-3119/lib/python3.11/site-packages/jsonargparse/_deprecated.py", line 124, in patched_parse
    cfg = parse_method(*args, _skip_check=_skip_check, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vinnamki/otx/training_extensions/.venv-3119/lib/python3.11/site-packages/jsonargparse/_core.py", line 390, in parse_args
    cfg, unk = self.parse_known_args(args=args, namespace=cfg)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vinnamki/otx/training_extensions/.venv-3119/lib/python3.11/site-packages/jsonargparse/_core.py", line 261, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/argparse.py", line 2140, in _parse_known_args
    start_index = consume_optional(start_index)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/argparse.py", line 2002, in consume_optional
    action, option_string, sep, explicit_arg = option_tuple
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 4, got 3)

Expected behavior

No error

Environment

mauvilsa commented 5 months ago

Thank you for reporting. The issue should be fixed with #486. Though, would be nice if you try it out with training_extensions. You could for example set as requirement jsonargparse @ https://github.com/omni-us/jsonargparse/zipball/argparse-parse-optional-breaking-change.

mauvilsa commented 4 months ago

@vinnamkim I merged the pull request so that tests stop failing. But please test it out if you can. If more fixes are needed, then better to do them before the next release.

vinnamkim commented 4 months ago

Hi @mauvilsa, Thanks for your quick action. Our CI looks green for your latest main branch https://github.com/openvinotoolkit/training_extensions/actions/runs/8657227615/job/23739085433?pr=3308