Skip to content

Fix issues with parsing models on Python 3.9#112

Merged
marcelveldt merged 3 commits intomainfrom
fix-uniontype
Dec 1, 2022
Merged

Fix issues with parsing models on Python 3.9#112
marcelveldt merged 3 commits intomainfrom
fix-uniontype

Conversation

@marcelveldt
Copy link
Copy Markdown
Collaborator

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
except: # noqa
# older python version
NoneType = type(None)
UnionType = type(int | str)
Copy link
Copy Markdown
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
Copy Markdown
Collaborator 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


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
Copy Markdown
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
Copy Markdown
Collaborator 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