question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PEP-563 breaks SerializationStrategy

See original GitHub issue
  1. SerializationStrategy example with DateTimeFormats works fine in py3.7 https://github.com/Fatal1ty/mashumaro#user-defined-classes

  2. however introduction of PEP-563 via from __future__ import annotations https://www.python.org/dev/peps/pep-0563/ breaks usage of SerializationStrategy with error trace:

Traceback (most recent call last):
  File ".../src/verify/code/mashu/mashu_pep563.py", line 22, in <module>
    class DateTimeFormats(DataClassDictMixin):
  File "/usr/lib/python3.7/site-packages/mashumaro/serializer/base/dict.py", line 19, in __init_subclass__
    raise exc
  File "/usr/lib/python3.7/site-packages/mashumaro/serializer/base/dict.py", line 15, in __init_subclass__
    builder.add_to_dict()
  File "/usr/lib/python3.7/site-packages/mashumaro/serializer/base/metaprogramming.py", line 163, in add_to_dict
    for fname, ftype in self.fields.items():
  File "/usr/lib/python3.7/site-packages/mashumaro/serializer/base/metaprogramming.py", line 53, in fields
    for fname, ftype in typing.get_type_hints(self.cls).items():
  File "/usr/lib/python3.7/typing.py", line 973, in get_type_hints
    value = _eval_type(value, base_globals, localns)
  File "/usr/lib/python3.7/typing.py", line 260, in _eval_type
    return t._evaluate(globalns, localns)
  File "/usr/lib/python3.7/typing.py", line 466, in _evaluate
    is_argument=self.__forward_is_argument__)
  File "/usr/lib/python3.7/typing.py", line 139, in _type_check
    raise TypeError(f"{msg} Got {arg!r:.100}.")
TypeError: Forward references must evaluate to types. Got <__main__.FormattedDateTime object at 0x7faec3540f60>.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Fatal1tycommented, Feb 23, 2021

I changed the way howSerializationStrategy classes are used. @rominf you might be interested in reading README here and here. At the moment these changes are in the master branch but I will release 2.0 version soon since it’s not backward compatible.

0reactions
Fatal1tycommented, Mar 2, 2021

The new changes are in 2.0 now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

PEP 563 getting rolled back from Python 3.10 - Reddit
This decision was made after third-party library maintainers (primarily Pydantic) raised an issue on how PEP 563 was going to break their ...
Read more >
mashumaro Changelog - pyup.io
Added support for PEP 563 postponed evaluation of annotations. ... Fixed broken serialization of data classes that also inherit another supported ...
Read more >
Type annotations, PEP 649 and PEP 563 - Core Development
Are there cases of type annotations for static checking or runtime use that PEP 563 enables, which would break with PEP 649? Is...
Read more >
PEP 563, PEP 649 and the future of pydantic and FastAPI
It's fine to wait more than two releases." PEP 563, the one that apparently breaks pydantic, was accepted during Python 3.7. This was...
Read more >
Sebastián Ramírez on Twitter: "Great news for pydantic and ...
Great news for pydantic and FastAPI The Python steering council decided to delay making PEP 563 the default until Python 3.11 It's a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found