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

Optional type hint schema generation support broken #426

Closed
johnthagen opened this issue Jul 29, 2019 · 2 comments · May be fixed by #840
Closed

Optional type hint schema generation support broken #426

johnthagen opened this issue Jul 29, 2019 · 2 comments · May be fixed by #840

Comments

@johnthagen
Copy link
Collaborator

johnthagen commented Jul 29, 2019

1.15.1 broke support for Optional type hinting schema generation.

Python versions on which the problem as been reproduced:

  • CPython 3.7.3
  • CPython 3.6.8
  • PyPy 7.1.1 (3.6 compatible)

To reproduce, create a Serializer like:

from typing import Optional

class MySerializer(Serializer):
    x = SerializerMethodField()

    def get_x(self, instance) -> Optional[int]:
        pass

In 1.15.0, this is properly detected in the generated schema as an integer.
In 1.16.0 (I couldn't get 1.15.1 to run properly), it is incorrectly detected as a string.

@johnthagen johnthagen changed the title Optional type hint support broken Optional type hint schema generation support broken Jul 30, 2019
@etene
Copy link
Contributor

etene commented Aug 1, 2019

I think you're right, it looks like it was broken in 69b628a by removing the if not inspect.isclass(hint_class) and hasattr(hint_class, '__args__'): check in SerializerMethodFieldInspector. I have a PR coming up.

@johnthagen
Copy link
Collaborator Author

#428 has been merged. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants