-
Notifications
You must be signed in to change notification settings - Fork 266
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
parameters supporting lazy strings are not typed as accepting them #982
Comments
This does not currently cause errors when type checking drf-spectacular itself because the django-stubs dependency was pinned to the version before that change: #693 (comment) and 799f394 But since that was more than one year ago, would it be possible to unpin it? |
Yes, we should check and lift the stubs pinning. Yes, accounting for promise str we should definitely support in the typing. Question is which type is the best here? We can't use something from the stubs package directly, as it may not be available in production. Conditional import might be an option. Or maybe just |
The django-stubs-ext could be added as a typecheck dependency and the import conditioned on |
Although I lean towards DIY for this seemingly simple thing, there is likely something more going on through the mypy django plugin. We also have to make sure we don't break users relying on other static type checkers like pyright. |
As they are defined in https://github.com/typeddjango/django-stubs/blob/master/django-stubs/utils/functional.pyi#L30 I don't see why they would not exist for those users. And if I understand correctly typeddjango/django-stubs#579, pyright does not break when django-stubs are applied without extension. Another option would be to try importing from |
I know this is not exactly what was discussed, but I thought I give the minimal version a try before introducing conditional importing and type checking branching. @nils-van-zuijlen, can you confirm this behaves as expected? |
allow already supported lazy string in types #982
Describe the bug
Updating to django-stubs to 1.13.0 and later, the
lazy
string functions from the translations module are declared as returningPromise
objects instead ofstr
.Most classes / functions in drf_spectacular are typed as accepting
str
only, but work well with lazy strings, and are now flagged by mypy.To Reproduce
Declare a response with the description set to a lazy translatable string.
Typecheck the code with mypy and django-stubs 1.13.0 or later.
Expected behavior
No typecheck error is raised, the translatable arguments are declared as allowing
StrOrPromise
References
https://github.com/typeddjango/django-stubs#why-am-i-getting-incompatible-argument-type-mentioning-_strpromise
The text was updated successfully, but these errors were encountered: