Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7k
Allow generic requests, responses, fields, views#8825
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
175ffd1 to4c51b60Comparelovelydinosaur commentedJan 2, 2023
Can you explain why this is useful? |
jalaziz commentedJan 2, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@tomchristie I've updated the PR description with more details. |
jalaziz commentedJan 2, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
To carry on the conversation from#7385. The types are being used to infer and check the types returned from methods like: Django has already shipped subscription for QuerySets and other classes which helps avoid the need for monkey patching, but DRF is still missing some key classes. |
c55dab3 to581fa59Comparejalaziz commentedJan 7, 2023
Rebased to ensure the tests pass. |
melotte25 commentedFeb 20, 2023
Not to be a pain, but could another reviewer such as@auvipy take a look at this? We're upgrading to the latest Thank you! |
lovelydinosaur commentedFeb 21, 2023
|
jalaziz commentedFeb 21, 2023
It doesn't solve a type-checking issue per se, it solves a problem that occurs when you try to monkey-patch type support. Will try to put up an example project to show the issue, but fundamentally the issue is, unlike Django, DRF eagerly loads settings on import which results in improper settings when trying to monkey patch classes too early.
Yes and no. Today,
Djangodoes support |
jalaziz commentedFeb 22, 2023
@tomchristie here's a test repo exhibiting some issues:https://github.com/jalaziz/drf-test-repo As it stands, we end up with no pagination because of the eager settings issue (despitepagination being set): For this repo, the workaround is to move the monkey patching to after the |
Allow Request, Response, Field, and GenericAPIView to be subscriptable.This allows the classes to be made generic for type checking.This is especially useful since monkey patching DRF can be problematicas seen in this [issue][1].[1]:typeddjango/djangorestframework-stubs#299
581fa59 toc066dfeCompare
lovelydinosaur left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Djangodoes support
__class_getitem__forQuerySets,Managers, andForeignKey.
This wins the case for you.
lovelydinosaur commentedFeb 22, 2023
Merging the latest |
auvipy commentedFeb 22, 2023
all green now! thanks |
auvipy commentedFeb 22, 2023
sorry I missed the notification |
mschoettle commentedDec 4, 2023
@tomchristie I ran into the issue explained in the PR description. Are there any plans to make a release containing this fix? |
mschoettle commentedDec 6, 2023
Or maybe@auvipy can answer the question about a release? |
auvipy commentedDec 6, 2023
Nope I can't. I don't have release access yet. |
pchabros commentedMar 18, 2024
It's still not released? |
Uh oh!
There was an error while loading.Please reload this page.
Description
Allow Request, Response, Field, and GenericAPIView to be subscriptable. This is a follow up to#7385 and allows the classes to be made generic for type checking.
By making these classes generic, type checkers can more easily do their job when working with DRF classes. Today,
django-stubs and djangorestframework-stubs must monkey patch types to support generic typing, but the approach is problematic with DRF since DRF eagerly loads settings resulting inissues like this.