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

Examples don't work in Python 3.6 #11

Closed
necaris opened this issue Aug 23, 2019 · 2 comments
Closed

Examples don't work in Python 3.6 #11

necaris opened this issue Aug 23, 2019 · 2 comments

Comments

@necaris
Copy link
Collaborator

necaris commented Aug 23, 2019

See #10 -- while the examples work fine in Python 3.7, it would be ideal if we could make them work (or document where they don't) in 3.6

@dantheman39
Copy link
Contributor

The issue seems to be here: https://github.com/upsidetravel/graphene-pydantic/blob/f0326a75c7c3e7b0b5dfa1aa58d0fd864da44705/examples/departments.py#L35

class DepartmentModel(pydantic.BaseModel):
    id: uuid.UUID
    name: str
    employees: T.List[T.Union[ManagerModel, EmployeeModel]]

employees is a Union of Manager and Employee, and Manager is a subclass of Employee. In 3.6, typing.py throws away direct subclasses in Unions, so in DepartmentModel.__annotations__, the employees field is listed as typing.List[__main__.EmployeeModel], and not typing.List[typing.Union[__main__.ManagerModel, __main__.EmployeeModel]] as in 3.7, so all of the introspection that we rely on has no way of knowing that employees is a Union of Manager and Employee, it just thinks it's an employee.

In the documentation for Union they explicitly note that subclasses are no longer thrown out as of python 3.7.

@necaris
Copy link
Collaborator Author

necaris commented Sep 2, 2019

Closed by #12

@necaris necaris closed this as completed Sep 2, 2019
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

2 participants