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

Fix issues with parsing models on Python 3.9 #112

Merged
merged 3 commits into from
Dec 1, 2022
Merged

Conversation

marcelveldt
Copy link
Contributor

Union types need to be written the oldskool way (even with annotations from future), otherwise our dynamic model creation does not work on python 3,9 causing import errors.

@marcelveldt marcelveldt merged commit 7050e2e into main Dec 1, 2022
@marcelveldt marcelveldt deleted the fix-uniontype branch December 1, 2022 00:05
@@ -35,7 +35,7 @@
except: # noqa
# older python version
NoneType = type(None)
UnionType = type(int | str)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason this doesn't work with from __future__ is because it is not written inside an annotation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, missed that while in the rush

@@ -87,15 +87,20 @@ def parse_utc_timestamp(datetimestr: str):
return datetime.fromisoformat(datetimestr.replace("Z", "+00:00"))


def parse_value(name: str, value: Any, value_type: Type | str, default: Any = MISSING):
def parse_value(
name: str, value: Any, value_type: Union[Type, str], default: Any = MISSING
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is inside an annotation so would have been fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, unrelated. The issue was the parsing of the actual annotations in this function itself.

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

Successfully merging this pull request may close these issues.

2 participants