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

Warning: "from __future__ import annotations" breaks "from_dict" #24

Open
Ogaday opened this issue May 28, 2020 · 0 comments
Open

Warning: "from __future__ import annotations" breaks "from_dict" #24

Ogaday opened this issue May 28, 2020 · 0 comments

Comments

@Ogaday
Copy link
Contributor

Ogaday commented May 28, 2020

eg:

from __future__ import annotations

from dataclasses import dataclass

from howard import from_dict, to_dict


@dataclass
class Number:
    value: int


d = {'value': 1}
from_dict(d, Number)
# TypeError: Unsupported type int

The error message is strange, because of course ints are supported! Here's what's actually happening: The Field object, who's type attribute we inspect as part of the loading routine, is usually a genuine python type. When annotations is imported, that attribute becomes a string representing the type instead.

from dataclasses import fields

fields(Number)[0].type
# 'int'

I'm not sure how to fix this, so I'm just leaving this issue here.

There is an issue on the Python bug tracker here, but it doesn't look very positive.

@Ogaday Ogaday changed the title Warning: from __future__ import annotations breaks from_dict Warning: "from __future__ import annotations" breaks "from_dict" May 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant