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

Raise an error on the latest Python 3.11.9 #484

Closed
vinnamkim opened this issue Apr 9, 2024 · 3 comments · Fixed by #486
Closed

Raise an error on the latest Python 3.11.9 #484

vinnamkim opened this issue Apr 9, 2024 · 3 comments · Fixed by #486
Labels
bug Something isn't working

Comments

@vinnamkim
Copy link

vinnamkim commented Apr 9, 2024

🐛 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

  • jsonargparse version (e.g., 4.8.0): 4.27.7
  • Python version (e.g., 3.9): 3.11.9
  • How jsonargparse was installed (e.g. pip install jsonargparse[all]): pip install jsonargparse
  • OS (e.g., Linux): Linux
@mauvilsa
Copy link
Member

mauvilsa commented Apr 9, 2024

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
Copy link
Member

@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
Copy link
Author

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

slowmoyang added a commit to slowmoyang/diffmet-training that referenced this issue Sep 1, 2024
- upgrade jsonargparse to fix a bug. see omni-us/jsonargparse#484
- specify the versions of some packages
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
2 participants