Skip to content

Selecting a subtype raises an exception in Python 3.12.7 #590

@eggry

Description

@eggry

🐛 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions