PIG208
a1445291fd
Improve type annotation for RunSQL ( #1090 )
...
* Allow passing heterogeneous list or tuple to RunSQL.
The sqls to be executed do not necessarily need to be a homogeneous list
or tuple containing only lists or tuples or strs. It can be a mix of
everything.
Signed-off-by: Zixuan James Li <p359101898@gmail.com >
* Support passing dict as a sql param.
The 2-item tuple for `sql` can have a `dict` as the second item
for parameters. This behavior is the same as using
`cursor.execute` for backends except SQLite.
Relevant implementation:
https://github.com/django/django/blob/5f760025004bdb02f9844011033459c30347f215/django/db/migrations/operations/special.py#L119-L133
Signed-off-by: Zixuan James Li <p359101898@gmail.com >
* Add a test case for RunSQL.
Signed-off-by: Zixuan James Li <p359101898@gmail.com >
2022-08-09 10:36:36 +03:00
PIG208
7b18e354f1
Add preset options list to makemessages command. ( #1091 )
...
These options can be found here:
https://github.com/django/django/blob/0756c61f2ada56e4ae625589099c0141a77737eb/django/core/management/commands/makemessages.py#L222-L225
Signed-off-by: Zixuan James Li <p359101898@gmail.com >
2022-08-09 00:31:34 +03:00
PIG208
db1edeeabf
Fix a broken test case after the Django 4.1 update. ( #1093 )
...
This fixes the CI starting occur on #1086 and following PRs due to the release
of Django 4.1 (https://docs.djangoproject.com/en/4.1/releases/4.1/ ) which
shipped the change
# Even if this relation is not to pk, we require still pk value.
# The wish is that the instance has been already saved to DB,
# although having a pk value isn't a guarantee of that.
if self.instance.pk is None:
raise ValueError(
f"{instance.__class__.__name__!r} instance needs to have a primary "
f"key value before this relationship can be used."
)
in https://github.com/django/django/pull/15318 .
2022-08-09 00:18:08 +03:00
PIG208
0e9ebf838b
Support Lookup generics. ( #1079 )
...
Custom `Lookup` implementation will run into
'Missing type parameters for generic type "Lookup"' without having
`Lookup` monkey-patched with django-stubs-ext.
Signed-off-by: Zixuan James Li <p359101898@gmail.com >
2022-07-28 21:08:56 +03:00
PIG208
56f9300d0d
Improve stubs for contrib.postgres.operations. ( #1071 )
...
* Improve stubs for contrib.postgres.operations.
This adds a bunch of missing operations in contrib.postgres.operations.
Documentation: https://docs.djangoproject.com/en/4.0/ref/contrib/postgres/operations/#managing-collations-using-migrations
Source code: https://github.com/django/django/blob/2fac0a18081dcc77fc860c801e5d727dc90435b3/django/contrib/postgres/operations.py
Signed-off-by: Zixuan James Li <p359101898@gmail.com >
* Add migration_name_fragment to Operation.
Signed-off-by: Zixuan James Li <p359101898@gmail.com >
* Remove redefinition of methods in subclasses.
Signed-off-by: Zixuan James Li <p359101898@gmail.com >
2022-07-24 10:40:13 +03:00
PIG208
f3f80164a8
Fix type annotation of message_dict. ( #1073 )
...
When message_dict is accessed, it either raises an `AttributeError` or
returns a `dict`. There is no way for it to be `Optional`.
https://github.com/django/django/blob/caad462feaa84ba78ed658a9595a4a4363dad2db/django/core/exceptions.py#L170-L176
Signed-off-by: Zixuan James Li <p359101898@gmail.com >
2022-07-23 16:55:58 +03:00
PIG208
563e947402
Improve type annotation of DiscoverRunner. ( #1069 )
...
The return type of DiscoverRunner.get_resultclass should
be Optional[Type[TextTestResult]] given that it may also return PDBDebugResult:
https://github.com/django/django/blob/0dd29209091280ccf34e07c9468746c396b7778e/django/test/runner.py#L958-L962
`DicoverRunner.run_tests` accepts `None` for `extra_tests` because
that's already the default value for it:
https://github.com/django/django/blob/0dd29209091280ccf34e07c9468746c396b7778e/django/test/runner.py#L1030
2022-07-22 10:34:26 +03:00
PIG208
3648e10350
Use _AsSqlType for as_sql ( #1052 )
...
* Annotate the return type of as_sql for SpatialOperator.
Its subclasses inherits the type annotation from `SpatialOperator`, so
copying `as_sql` over is unnecessary.
Signed-off-by: Zixuan James Li <p359101898@gmail.com >
* Remove unnecessary as_sql definition.
`Query` inherits `as_sql` from `BaseExpression`, `GISLookup` inherits
`as_sql` from `Lookup`, and `BuiltinLookup` inherits `as_sql` from
`Lookup[_T]`. None is required to be redefined.
Signed-off-by: Zixuan James Li <p359101898@gmail.com >
* Unify return types of as_sql and friends as _AsSqlType.
`Tuple[str, _ParamsT]`, `Tuple[str, List[Union[str, int]]]` and other
similar type annotations are all replaced with the `_AsSqlType`
alias. Any as_sql definition that annotate the return type as `Any` is also
updated to use `_AsSqlType`.
Signed-off-by: Zixuan James Li <p359101898@gmail.com >
2022-07-13 09:47:01 +03:00
PIG208
516deba2fa
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 >
2022-07-04 23:46:53 +03:00
PIG208
0d8dd85442
Minor fixes to improve django-stubs ( #695 )
...
* Use `Sequence` instead of `Iterable` for `send_messages`.
According to the documentation
(https://docs.djangoproject.com/en/3.2/topics/email/#email-backends ),
`email_messages` is a list. Using `Iterable` will make it hard for
subclasses to implement this method utilizing functions like `__len__`.
While this still allows subclasses to accept `Iterable`.
* Fix function signature of `authenticate` of `BaseBackend`.
1. BaseBackend no longer requires the username and password argument.
They were removed 3 years ago in the commit below when `BaseBackend` is added:
https://github.com/django/django/commit/75337a60509fdfdd321a5caf8e30d57fff6b9518
2. `request` is optional for `authenticate` method.
According to django documentation, the authenticate method does not
necessarily require the request object.
https://docs.djangoproject.com/en/3.2/topics/auth/default/#authenticating-users
* Tighten the type of `streaming_content` to `Iterator[bytes]`.
It is an iterator of a bytestring according to the documentation:
https://docs.djangoproject.com/en/3.2/ref/request-response/#django.http.StreamingHttpResponse.streaming_content
* Fix function signature of `django.contrib.staticfiles.serve`.
Since this `serve` function uses `django.views.static.serve` that
accepts `HttpRequest` as its first argument, it is more reasonable
to type it with `HttpRequest` instead of `WSGIRequest`.
Related:
https://github.com/django/django/blob/main/django/contrib/staticfiles/views.py#L39
2021-08-16 10:59:04 +03:00
PIG208
a6a81797d3
Add py.typed to package distribution of django_stubs_ext. ( #694 )
2021-08-15 17:52:44 +03:00
PIG208
8674c48c59
Fixes a broken link in CONTRIBUTING.md ( #690 )
2021-08-12 19:50:29 +03:00