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

What type int must I use? #199

Closed
tonioo opened this issue Nov 13, 2020 · 4 comments
Closed

What type int must I use? #199

tonioo opened this issue Nov 13, 2020 · 4 comments
Labels
enhancement New feature or request fix confirmation pending issue has been fixed and confirmation from issue reporter is pending

Comments

@tonioo
Copy link

tonioo commented Nov 13, 2020

I have a field represented by a SerializerMethodField which returns a list of string. I have tried different things to indicate the type (using the @extend_schema and a type hint) but I always receive the same warning:

Warning #0: type hint for function "get_domains" is unknown. consider using a type hint or @extend_schema_field. defaulting to string.

Any help appreciated :)

@tfranzel
Copy link
Owner

hi @tonioo, so the type hint support is currently very minimal (basic py types & Optional[]). so no lists/dicts supported yet. i suppose #198 suffers from the same problem. this feature is simply not complete yet. let me provide a patch to extend the support. i will have a look there.

@tfranzel tfranzel added the enhancement New feature or request label Nov 14, 2020
tfranzel added a commit that referenced this issue Nov 14, 2020
@tfranzel
Copy link
Owner

i overlooked that you used @extend_schema, which is not applicable here. it is for views, view methods but not serializer methods. the correct decorator would be @extend_schema_field, just as the warning says. 😄 have a look at those examples:

https://github.com/tfranzel/drf-spectacular/blob/master/tests/test_extend_schema.py#L55

but the type hints needed work anyway. with this fix, type hint resolution covers a lot more cases now including dict, list, tuple, and so on.

@tfranzel tfranzel added the fix confirmation pending issue has been fixed and confirmation from issue reporter is pending label Nov 14, 2020
@tfranzel
Copy link
Owner

@tonioo can you confirm the fix solves your issue?

@tonioo
Copy link
Author

tonioo commented Nov 18, 2020

@tfranzel I confirm it works now, the type hint is correctly recognized!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request 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