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

feat: add support for dataclasses._MISSING_TYPE #1137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions omegaconf/omegaconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import warnings
from collections import defaultdict
from dataclasses import _MISSING_TYPE
from contextlib import contextmanager, nullcontext
from enum import Enum
from textwrap import dedent
Expand Down Expand Up @@ -845,6 +846,8 @@ def _create_impl( # noqa F811

if obj is _DEFAULT_MARKER_:
obj = {}
if isinstance(obj, _MISSING_TYPE):
return OmegaConf.create({}, parent=parent, flags=flags)
if isinstance(obj, str):
obj = yaml.load(obj, Loader=get_yaml_loader())
if obj is None:
Expand Down
23 changes: 23 additions & 0 deletions tests/test_missing_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from dataclasses import dataclass, field
from typing import List, Any
from omegaconf import OmegaConf


@dataclass
class Example:
num: int


@dataclass
class TestConfig(Example):
common: Example = field(default_factory=Example)


for k, field_info in TestConfig.__dataclass_fields__.items():
default_value = field_info.default
default_factory = field_info.default_factory
print(
f"Field: {k}, Default Value: {default_value}, Default Factory: {default_factory}"
)

mis = OmegaConf.structured(default_factory)