lidatong / dataclasses-json

Easily serialize Data Classes to and from JSON
MIT License
1.34k stars 151 forks source link

Fixes bug related to Tuples defined with ellipsis #440

Closed matt035343 closed 11 months ago

matt035343 commented 11 months ago

PR https://github.com/lidatong/dataclasses-json/pull/435 introduced a new bug that raises an exception when deserializing tuples defined with ellipsis (e.g. Tuple[str, ...]). This PR is fixing this issue.

github-actions[bot] commented 11 months ago

Coverage

Coverage Report
FileStmtsMissCoverMissing
dataclasses_json
   cfg.py51492%77, 81–83
   core.py234996%38–41, 51, 64, 66, 81, 83, 169
   mm.py1892985%33–36, 42–45, 53–56, 62–65, 88, 152–153, 158, 162, 166, 171, 175, 179, 187, 193, 198, 207, 212, 217, 235–242
   stringcase.py25388%59, 76, 97
   undefined.py143299%24, 38
   utils.py1282977%11–24, 44–49, 60–64, 74, 99–100, 108–109, 158, 177, 202
tests
   entities.py220299%229, 235
   test_annotations.py814248%50–67, 78–102, 106–122
   test_api.py142299%139–140
   test_str_subclass.py22195%9
TOTAL242212395% 

Tests Skipped Failures Errors Time
283 1 :zzz: 0 :x: 0 :fire: 4.631s :stopwatch:
deansg commented 11 months ago

The bug still seems to happen, I have a Tuple[str, ...] as a field in a class and just calling .schema() on it fails with the following message: E TypeError: Field.__init__() takes 1 positional argument but 2 positional arguments (and 3 keyword-only arguments) were given

deansg commented 11 months ago

Full code to reproduce on Python 3.10 (very straightforward):

@dataclass_json
@dataclass
class SomeClass:
    tags: Tuple[str, ...] = None

def test_foo():
    SomeClass.schema()
matt035343 commented 11 months ago

Hi @deansg. If I am not mistaken, this seems to be related to an old issue (#398 and #432) not directly related to what has been discussed in #440 and #435. I will have a look at #398 soon.