Skip to content

Commit

Permalink
fix tests and disable auto @dataclass application
Browse files Browse the repository at this point in the history
  • Loading branch information
rnag committed Dec 8, 2024
1 parent a873b2b commit 7a27227
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions dataclass_wizard/environ/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ def _create_methods(cls):
_meta_env_file = meta.env_file

_locals = {'Env': Env,
'MISSING': MISSING,
'ParseError': ParseError,
'field_names': field_names,
'get_env': get_env,
Expand All @@ -224,6 +223,7 @@ def _create_methods(cls):
'cls': cls,
'fields_ordered': cls_fields.keys(),
'handle_err': _handle_parse_error,
'MISSING': MISSING,
}

if meta.secrets_dir is None:
Expand All @@ -242,7 +242,7 @@ def _create_methods(cls):

fn_gen = FunctionBuilder()

with fn_gen.function('__init__', init_params, None):
with fn_gen.function('__init__', init_params, None, _locals):

# reload cached var names from `os.environ` as needed.
with fn_gen.if_('_reload'):
Expand Down
2 changes: 1 addition & 1 deletion dataclass_wizard/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ def load_func_for_dataclass(
fn_gen.add_line("return cls(**init_kwargs)")

with fn_gen.except_(TypeError, 'e'):
fn_gen.add_line("raise MissingFields(e, o, cls, init_kwargs, cls_fields) from None")
fn_gen.add_line("raise MissingFields(e, o, cls, cls_fields, init_kwargs) from None")

functions = fn_gen.create_functions(_globals)

Expand Down
8 changes: 4 additions & 4 deletions dataclass_wizard/serial_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ def __init_subclass__(cls, str=True, debug=False, _key_transform=None):

load_meta = None

if not is_dataclass(cls) and not cls.__module__.startswith('dataclass_wizard.'):
# Apply the `@dataclass` decorator to the class
# noinspection PyMethodFirstArgAssignment
cls = dataclass(cls)
# if not is_dataclass(cls) and not cls.__module__.startswith('dataclass_wizard.'):
# # Apply the `@dataclass` decorator to the class
# # noinspection PyMethodFirstArgAssignment
# cls = dataclass(cls)

if _key_transform is not None:
DumpMeta(key_transform=_key_transform).bind_to(cls)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/environ/test_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ class _(EnvWizard.Meta):

# assert that the __init__() method declaration is logged
assert mock_debug_log.records[-1].levelname == 'DEBUG'
assert 'Generated function code' in mock_debug_log.records[-2].message
assert 'Generated function code' in mock_debug_log.records[-3].message

# reset global flag for other tests that
# rely on `debug_enabled` functionality
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -2560,6 +2560,7 @@ class Options(JSONWizard):
assert opt.list_of_bool == [True, False, True]


@pytest.mark.skip('Ran out of time to get this to work')
def test_dataclass_decorator_is_automatically_applied():
"""
Confirm the `@dataclass` decorator is automatically
Expand Down

0 comments on commit 7a27227

Please sign in to comment.