mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-16 00:37:11 +08:00
Don't change type of HttpRequest.user if type has been changed by subclassing (#415)
* Don't change type of HttpRequest.user if type has been changed by subclassing * Asserts for typing * Add tests * Add description of HttpRequest subclassing to README * Dummy to rebuild travis
This commit is contained in:
committed by
GitHub
parent
b1d619edb2
commit
3704d0ab98
@@ -27,3 +27,28 @@
|
||||
reveal_type(request.user) # N: Revealed type is 'django.contrib.auth.models.User'
|
||||
custom_settings: |
|
||||
INSTALLED_APPS = ('django.contrib.contenttypes', 'django.contrib.auth')
|
||||
- case: subclass_request_not_changed_user_type
|
||||
disable_cache: true
|
||||
main: |
|
||||
from django.http.request import HttpRequest
|
||||
class MyRequest(HttpRequest):
|
||||
foo: int # Just do something
|
||||
|
||||
request = MyRequest()
|
||||
reveal_type(request.user) # N: Revealed type is 'Union[django.contrib.auth.models.User, django.contrib.auth.models.AnonymousUser]'
|
||||
custom_settings: |
|
||||
INSTALLED_APPS = ('django.contrib.contenttypes', 'django.contrib.auth')
|
||||
|
||||
- case: subclass_request_changed_user_type
|
||||
disable_cache: true
|
||||
main: |
|
||||
from django.http.request import HttpRequest
|
||||
from django.contrib.auth.models import User
|
||||
class MyRequest(HttpRequest):
|
||||
user: User # Override the type of user
|
||||
|
||||
request = MyRequest()
|
||||
reveal_type(request.user) # N: Revealed type is 'django.contrib.auth.models.User'
|
||||
custom_settings: |
|
||||
INSTALLED_APPS = ('django.contrib.contenttypes', 'django.contrib.auth')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user