-
Notifications
You must be signed in to change notification settings - Fork 152
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
Library is not compatible with "from __future__ import annotations" (PEP 563) #62
Comments
To get the types we must call
The only caveat with this approach is that for classes that use forward references (with the class name itself) the |
Summary: There's an [issue](lidatong/dataclasses-json#62) with dataclasses_json supporting `from __future__ import annotations`. This diff: - Removes `from __future__ import annotations` - adds `mm_field` argument to `dataclasses.field` The second bullet point seems like it wouldn't be necessary but it was the only thing that got the error message to go away. It seems like it fixed the false negative on `ValidationError`s as well. Alternative options to this would be: - remove reliance on dataclasses_json This is a long term solution that we might want especially when newer python versions implicitly include `from __future__ import annotations`. It requires reworking the entirety of `code_navigation_request` so I am leaving it for the future. - Fully rely on `dataclasses_json` We can't do this that well because we need to override certain json encodings because of the protocol. Reviewed By: stroxler, grievejia Differential Revision: D43201933 fbshipit-source-id: 29e769a4a3c2c50c031a6602c7ff786593978b1b
PEP 563 means that we cannot expect type annotations to actually be class objects. Example code that fails (Python 3.7):
which outputs
The expected behavior is that
t
is of typeT
and not a dict. This works as expected whenfrom future import __annotations__
is commented out.The text was updated successfully, but these errors were encountered: