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

Union typing on model property #284

Closed
LukasBerka opened this issue Feb 2, 2021 · 2 comments
Closed

Union typing on model property #284

LukasBerka opened this issue Feb 2, 2021 · 2 comments
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending

Comments

@LukasBerka
Copy link

LukasBerka commented Feb 2, 2021

Describe the bug
The resolve_type_hint method inside plumbing.py does not recognize a hint in form:

def my_model_method(self) -> Union[None, OtherType]:
    pass

because the resolve_type_hint checks specifically for isinstance(None, args[1]).
on line 834.

so the same method with switched types in Union does work as expected

def my_model_method(self) -> Union[OtherType, None]:
    pass

Using
Python 3.9
drf-spectacular == 0.13.1
djangorestframework == 3.12.2

Expected behavior
I would assume that the order of types in Union does not matter as Python documentation says.
https://docs.python.org/3/library/typing.html#typing.Union

@tfranzel
Copy link
Owner

tfranzel commented Feb 2, 2021

certainly a bug or rather incomplete parsing. the rationale behind it was that this gets automatically translated Optional[OtherType] -> Union[OtherType, None].

@tfranzel tfranzel added the bug Something isn't working label Feb 2, 2021
@tfranzel tfranzel added the fix confirmation pending issue has been fixed and confirmation from issue reporter is pending label Feb 7, 2021
@tfranzel
Copy link
Owner

closing this issue for now. feel free to comment if anything is missing or not working and we will follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fix confirmation pending issue has been fixed and confirmation from issue reporter is pending
Projects
None yet
Development

No branches or pull requests

2 participants