Skip to content

Commit

Permalink
Allow variadic tuples of length 0. Fixes #104
Browse files Browse the repository at this point in the history
  • Loading branch information
intentionally-left-nil committed Jan 14, 2024
1 parent e3fe076 commit f802ce4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,6 @@ venv/
ENV/
env.bak/
venv.bak/

# File created by pytest
testing.json
5 changes: 1 addition & 4 deletions dataclass_wizard/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,7 @@ def __post_init__(self, cls: Type,
# Total count should be `Infinity` here, since the variadic form
# accepts any number of possible arguments.
self.total_count: N = float('inf')
# Check for the count of parsers which don't handle `NoneType` - this
# should exclude the parsers for `Union` types that have `None` in the
# list of args.
self.required_count = 0 if None in self.first_elem_parser[0] else 1
self.required_count = 0

def __call__(self, o: M) -> M:
"""
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,8 @@ class MyClass(JSONSerializable):
# conversion to `int` still succeeds. Might need to change this
# behavior later if needed.
[{}], does_not_raise(), (0, )),
(
[], does_not_raise(), tuple()),
(
[True, False, True], pytest.raises(TypeError), None),
(
Expand Down

0 comments on commit f802ce4

Please sign in to comment.