mirror of
https://github.com/davidhalter/django-stubs.git
synced 2026-04-29 10:14:38 +08:00
Improve stubs with minor fixes (#1038)
* Add a missing attribute to Jinja2. https://github.com/django/django/blob/main/django/template/backends/jinja2.py#L35 Signed-off-by: Zixuan James Li <p359101898@gmail.com> * Make _QuerySet.extra's signature more generic. This makes sure that we don't reject tuples, which is also valid according to the implementation. Relevant source code: https://github.com/django/django/blob/03eec9ff6cc78e7c1bcf88bb76ecd11f0d433c72/django/db/models/sql/where.py#L271-L281 https://github.com/django/django/blob/03eec9ff6cc78e7c1bcf88bb76ecd11f0d433c72/django/db/models/sql/query.py#L2307-L2308 Signed-off-by: Zixuan James Li <p359101898@gmail.com> * Fix user_passes_test to use AUTH_USER_MODEL. According to the documentation, `test_func` is a callable that takes a `User` (possibly anonymous). Relevant documentation: https://docs.djangoproject.com/en/4.0/topics/auth/default/#django.contrib.auth.decorators.user_passes_test Signed-off-by: Zixuan James Li <p359101898@gmail.com> * Add more accurate type annotations for dirs. Though not documented, it's possible for `dirs` to contain `pathlib.Path`. `django.template.loaders.app_directories.Loader` is an example for this: https://github.com/django/django/blob/03eec9ff6cc78e7c1bcf88bb76ecd11f0d433c72/django/template/loaders/app_directories.py https://github.com/django/django/blob/03eec9ff6cc78e7c1bcf88bb76ecd11f0d433c72/django/template/utils.py#L97-L111 Signed-off-by: Zixuan James Li <p359101898@gmail.com> * serve should return FileResponse. There are several serve functions that should return a `FileResponse`. Source code: https://github.com/django/django/blob/863aa7541d30247e7eb7a973ff68a7d36f16dc02/django/views/static.py#L17-L53 https://github.com/django/django/blob/863aa7541d30247e7eb7a973ff68a7d36f16dc02/django/contrib/staticfiles/views.py#L15-L39 https://github.com/django/django/blob/863aa7541d30247e7eb7a973ff68a7d36f16dc02/django/contrib/staticfiles/handlers.py#L48-L50 https://github.com/django/django/blob/863aa7541d30247e7eb7a973ff68a7d36f16dc02/django/test/testcases.py#L1680-L1687 Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
@@ -27,14 +27,14 @@
|
||||
- case: user_passes_test
|
||||
main: |
|
||||
from django.contrib.auth.decorators import user_passes_test
|
||||
@user_passes_test(lambda u: u.username.startswith('super'))
|
||||
@user_passes_test(lambda u: u.get_username().startswith('super'))
|
||||
def view_func(request): ...
|
||||
reveal_type(view_func) # N: Revealed type is "def (request: Any) -> Any"
|
||||
- case: user_passes_test_bare_is_error
|
||||
main: |
|
||||
from django.http.response import HttpResponse
|
||||
from django.contrib.auth.decorators import user_passes_test
|
||||
@user_passes_test # E: Argument 1 to "user_passes_test" has incompatible type "Callable[[Any], HttpResponse]"; expected "Callable[[AbstractUser], bool]"
|
||||
@user_passes_test # E: Argument 1 to "user_passes_test" has incompatible type "Callable[[Any], HttpResponse]"; expected "Callable[[Union[AbstractBaseUser, AnonymousUser]], bool]"
|
||||
def view_func(request) -> HttpResponse: ...
|
||||
- case: permission_required
|
||||
main: |
|
||||
|
||||
@@ -407,7 +407,7 @@
|
||||
reveal_type(MyModel.objects.difference) # N: Revealed type is "def (*other_qs: Any) -> myapp.models.MyQuerySet[myapp.models.MyModel]"
|
||||
reveal_type(MyModel.objects.distinct) # N: Revealed type is "def (*field_names: Any) -> myapp.models.MyQuerySet[myapp.models.MyModel]"
|
||||
reveal_type(MyModel.objects.exclude) # N: Revealed type is "def (*args: Any, **kwargs: Any) -> myapp.models.MyQuerySet[myapp.models.MyModel]"
|
||||
reveal_type(MyModel.objects.extra) # N: Revealed type is "def (select: Union[builtins.dict[builtins.str, Any], None] =, where: Union[builtins.list[builtins.str], None] =, params: Union[builtins.list[Any], None] =, tables: Union[builtins.list[builtins.str], None] =, order_by: Union[typing.Sequence[builtins.str], None] =, select_params: Union[typing.Sequence[Any], None] =) -> myapp.models.MyQuerySet[myapp.models.MyModel]"
|
||||
reveal_type(MyModel.objects.extra) # N: Revealed type is "def (select: Union[builtins.dict[builtins.str, Any], None] =, where: Union[typing.Sequence[builtins.str], None] =, params: Union[typing.Sequence[Any], None] =, tables: Union[typing.Sequence[builtins.str], None] =, order_by: Union[typing.Sequence[builtins.str], None] =, select_params: Union[typing.Sequence[Any], None] =) -> myapp.models.MyQuerySet[myapp.models.MyModel]"
|
||||
reveal_type(MyModel.objects.filter) # N: Revealed type is "def (*args: Any, **kwargs: Any) -> myapp.models.MyQuerySet[myapp.models.MyModel]"
|
||||
reveal_type(MyModel.objects.intersection) # N: Revealed type is "def (*other_qs: Any) -> myapp.models.MyQuerySet[myapp.models.MyModel]"
|
||||
reveal_type(MyModel.objects.none) # N: Revealed type is "def () -> myapp.models.MyQuerySet[myapp.models.MyModel]"
|
||||
|
||||
Reference in New Issue
Block a user