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

Support PEP563 lazy type evaluation #112

Closed
yukinarit opened this issue Apr 13, 2021 · 1 comment · Fixed by #126
Closed

Support PEP563 lazy type evaluation #112

yukinarit opened this issue Apr 13, 2021 · 1 comment · Fixed by #126
Assignees
Labels
enhancement New feature or request

Comments

@yukinarit
Copy link
Owner

Adding from __future__ import annotations to examples/simple.py raises an exception.

from __future__ import annotations
from dataclasses import dataclass

from serde import deserialize, serialize
from serde.json import from_json, to_json


@deserialize
@serialize
@dataclass
class Foo:
    i: int
    s: str
    f: float
    b: bool


def main():
    f = Foo(i=10, s='foo', f=100.0, b=True)
    print(f"Into Json: {to_json(f)}")

    s = '{"i": 10, "s": "foo", "f": 100.0, "b": true}'
    print(f"From Json: {from_json(Foo, s)}")


if __name__ == '__main__':
    main()
Into Json: {"i": null, "s": null, "f": null, "b": null}
Traceback (most recent call last):
  File "/Users/yukinari/repos/pyserde/examples/simple.py", line 27, in <module>
    main()
  File "/Users/yukinari/repos/pyserde/examples/simple.py", line 23, in main
    print(f"From Json: {from_json(Foo, s)}")
  File "/Users/yukinari/repos/pyserde/serde/json.py", line 29, in from_json
    return from_dict(c, de.deserialize(s, **opts), reuse_instances=False)
  File "/Users/yukinari/repos/pyserde/serde/de.py", line 274, in from_dict
    return from_obj(cls, o, named=True, reuse_instances=reuse_instances)
  File "/Users/yukinari/repos/pyserde/serde/de.py", line 211, in from_obj
    return serde_scope.funcs[FROM_DICT](o, reuse_instances=reuse_instances)
  File "<string>", line 16, in from_dict
  File "/Users/yukinari/repos/pyserde/serde/core.py", line 82, in raise_unsupported_type
    raise SerdeError(f"Unsupported type: {typename(type(obj))}")
serde.core.SerdeError: Unsupported type: int
@yukinarit yukinarit added the enhancement New feature or request label Apr 13, 2021
@yukinarit yukinarit self-assigned this Apr 15, 2021
@yukinarit
Copy link
Owner Author

@yukinarit yukinarit changed the title Support lazy type evaluation Support PEP563 lazy type evaluation Apr 21, 2021
@yukinarit yukinarit assigned ydylla and unassigned yukinarit May 11, 2021
yukinarit added a commit that referenced this issue May 13, 2021
Add support for lazy type annotations PEP563 (#112)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants