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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] instantiate: top-level _target_ has inconsistent behavior with _convert_ #2507

Open
Jasha10 opened this issue Dec 17, 2022 · 0 comments
Labels

Comments

@Jasha10
Copy link
Collaborator

Jasha10 commented Dec 17, 2022

馃悰 Bug

Description

The _convert_ flag has no effect when instantiating a config that has a _target_ at the top level.

To reproduce

from dataclasses import dataclass

import hydra
from omegaconf import DictConfig
from pytest import raises

@dataclass
class MyDataclass:
    ...

cfg = {"_target_": "__main__.MyDataclass"}

obj = hydra.utils.instantiate(cfg, _convert_="none")
with raises(AssertionError):
    assert isinstance(obj, DictConfig)  # got MyDataclass

obj = hydra.utils.instantiate(cfg, _convert_="partial")
with raises(AssertionError):
    assert isinstance(obj, DictConfig)  # got MyDataclass

obj = hydra.utils.instantiate(cfg, _convert_="object")
assert isinstance(obj, MyDataclass)  # Ok

obj = hydra.utils.instantiate(cfg, _convert_="all")
with raises(AssertionError):
    assert isinstance(obj, dict)  # got MyDataclass

Expected Behavior

None of the above assertions should raise an AssertionError; _convert_ should have the same effect for top-level configs as for nested configs.

System information

  • Hydra Version : 1.4.0.dev0
  • Python version : 3.10.8

Additional context

Based on bug report #2504.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant