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

In python 3.11, add_subclass_arguments with list[Class] is not working. #456

Open
harimkang opened this issue Feb 22, 2024 · 1 comment
Open
Labels
bug Something isn't working

Comments

@harimkang
Copy link

harimkang commented Feb 22, 2024

🐛 Bug report

Hi all, I'm working on a project that utilizes this great library.
However, I ran into a problem with python 3.11.

scheduler:
  - class_path: otx.algo.schedulers.warmup_schedulers.LinearWarmupScheduler
    init_args:
      num_warmup_steps: 10
  - class_path: lightning.pytorch.cli.ReduceLROnPlateau
    init_args:
      mode: max
      factor: 0.5
      patience: 1
      monitor: val/accuracy
parser.add_subclass_arguments(
            baseclass=(LRScheduler, ReduceLROnPlateau, list[LRSchedulerTypeUnion]),
            nested_key="scheduler",
            **scheduler_kwargs,
        )

I've been configuring arguments like the one above in project, which is mainly python 3.10 (& 3.9), but this doesn't work since python 3.11.
The reason for this is that as of python 3.11, list[Optimizer] is False in inspect.isclass().

if not baseclass or not all(inspect.isclass(c) for c in baseclass):
raise ValueError(f"Expected 'baseclass' argument to be a class or a tuple of classes: {baseclass}")

If I comment out that if statement and the raise statement, this works fine.
Do I need to use a different method to use list[Optimizer] or list[Scheduler]?
This used to work in python 3.9 and 3.10, but a new workaround is needed in 3.11.

I was wondering if could relax that if statement to make it more flexible.

To reproduce

Expected behavior

Environment

  • jsonargparse version (e.g., 4.8.0):
  • Python version (e.g., 3.9):
  • How jsonargparse was installed (e.g. pip install jsonargparse[all]):
  • OS (e.g., Linux):
@harimkang harimkang added the bug Something isn't working label Feb 22, 2024
@harimkang harimkang changed the title In python 3.11, add_subclass_arguments with list[Optimizer] is not working. In python 3.11, add_subclass_arguments with list[Class] is not working. Feb 22, 2024
@mauvilsa
Copy link
Member

Thank you for reporting! It does seem to be a bug. I will look at it.

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