dataclasses-json icon indicating copy to clipboard operation
dataclasses-json copied to clipboard

typing.Any is broken (regression)

Open pauldraper opened this issue 3 years ago • 1 comments

Situation

import dataclasses
import dataclasses_json
import typing

@dataclasses.dataclass
@dataclasses_json.dataclass_json
class Example:
    any: typing.Any

Example.schema()

Expected behavior

No error.

Actual behavior

Error.

Traceback (most recent call last):
  File "test3.py", line 10, in <module>
    Example.schema()
  File "/home/paul/.local/lib/python3.8/site-packages/dataclasses_json/api.py", line 100, in schema
    Schema = build_schema(cls, DataClassJsonMixin, infer_missing, partial)
  File "/home/paul/.local/lib/python3.8/site-packages/dataclasses_json/mm.py", line 359, in build_schema
    schema_ = schema(cls, mixin, infer_missing)
  File "/home/paul/.local/lib/python3.8/site-packages/dataclasses_json/mm.py", line 303, in schema
    if len(type_.__args__) == 2:
AttributeError: '_SpecialForm' object has no attribute '__args__'

This fails in version 0.5.2, but worked as expected in version 0.3.7.

pauldraper avatar Apr 23 '21 21:04 pauldraper

Still present in 0.5.6 and 0.5.7

tamassoltesz avatar Apr 12 '22 12:04 tamassoltesz

JSON doesn't have types like Any. This will always throw as we can't establish a ser-deser contract for this type. TLDR, doing to-from conversion will not work. Error message could be better - feel free to submit a PR for that :)

george-zubrienko avatar Jul 02 '23 17:07 george-zubrienko