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

Selecting a subtype raises an exception in Python 3.12.7 #590

Closed
eggry opened this issue Oct 5, 2024 · 1 comment
Closed

Selecting a subtype raises an exception in Python 3.12.7 #590

eggry opened this issue Oct 5, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@eggry
Copy link
Contributor

eggry commented Oct 5, 2024

🐛 Bug report

To reproduce

First, create a file named demo.py with the following content:

from typing import Optional
from jsonargparse import CLI

class Foo: ...

class Bar(Foo):
    def __init__(self, val: int) -> None:
        self.val = val

def main(data: Optional[Foo] = None) -> None:
    print(data)

if __name__ == "__main__":
    CLI(main)

Then, run the following command in your terminal:

python demo.py --data Bar --data.val 1

The output is:

usage: demo.py [-h] [--config CONFIG] [--print_config[=flags]] [--data.help CLASS_PATH_OR_NAME] [--data DATA]
error: cannot unpack non-iterable ActionTypeHint object

Such behavior will also affect LitGPT. For example, the command

    litgpt finetune tiiuae/falcon-7b \
        --data JSON \
        --data.json_path data/mydata.json \
        --out_dir data/mydata-finetuned

will also result in the same error because JSON is a subclass of DataModule.

Expected behavior

On Python 3.12.6, the output is:

<__main__.Bar object at 0x*******>

Environment

  • jsonargparse version: 4.32.1
  • Python version: 3.12.7
  • How jsonargparse was installed: pip install jsonargparse==4.32.1
  • OS: 22.04.3-Ubuntu
@eggry eggry added the bug Something isn't working label Oct 5, 2024
eggry added a commit to eggry/jsonargparse that referenced this issue Oct 5, 2024
mauvilsa pushed a commit that referenced this issue Oct 7, 2024
@mauvilsa
Copy link
Member

mauvilsa commented Oct 7, 2024

Fixed with #591

@mauvilsa mauvilsa closed this as completed Oct 7, 2024
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

No branches or pull requests

2 participants