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

Deprecate subclassing dict #707

Merged
merged 14 commits into from
May 11, 2021
2 changes: 1 addition & 1 deletion omegaconf/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ def extract_dict_subclass_data(obj: Any, parent: Any) -> Optional[Dict[str, Any]
warnings.warn(
"Subclassing of `Dict` by Structured Config classes is deprecated",
UserWarning,
stacklevel=2,
stacklevel=1,
)
Copy link
Collaborator Author

@Jasha10 Jasha10 May 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With stacklevel=2 we get a warning that looks like this:

$ python tmp.py
/home/jbss/omegaconf.git/omegaconf/_utils.py:373: UserWarning: Subclassing of `Dict` by Structured Config classes is deprecated
  dict_subclass_data = extract_dict_subclass_data(obj=obj, parent=dummy_parent)

With stacklevel=1 we get a warning that looks like this:

$ python tmp.py
/home/jbss/omegaconf.git/omegaconf/_utils.py:240: UserWarning: Subclassing of `Dict` by Structured Config classes is deprecated
  warnings.warn(

I changed 2 -> 1 because I thought the dict_subclass_data = extract_dict_subclass_data(...) was confusing...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exact interesting stack frame is probably not in a fixed depth.
Try to get it to issue the line calling OmegaConf.create() in the simple case.

Also, add the name of the type subclassing Dict to the warning.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 6eeb616 and 71ad2b6.


if isinstance(obj, type):
Expand Down