Commit Graph
471 Commits
Author SHA1 Message Date
rolandcrosby-checkandGitHub 1da693ebff Fix extra_context argument type in admin views (#816)
The `extra_context` argument to `ModelAdmin.changeform_view`,
`add_view`, `change_view`, `changelist_view`, `delete_view`, and
`history_view` is used to pass extra context variables to a template, so
all of these arguments should have type `Optional[Dict[str, Any]]`.
Instead, these are currently typed as `Optional[Dict[str, bool]]`,
`Optional[Dict[str, str]]`, or `None`.
2022-01-13 23:03:03 +03:00
rolandcrosby-checkandGitHub 3c1e9e3884 Allow Iterable[Iterable[Any]] as args_generator argument to format_html_join (#722)
* Allow List[Tuple[Any]] as args_generator argument to format_html_join

format_html_join's args_generator argument can be anything that contains
tuples of things that can be coerced to strings or that have a
`__html__` method.

Fixes #721.

* Use `Iterable[Iterable[Any]]` as `args_generator` type

* Run linter
2022-01-12 09:44:14 +03:00
rolandcrosby-checkandGitHub 7701957e4f Fix annotation of ModelAdmin.get_object (#812)
* Fix annotation of ModelAdmin.get_object

The type annotation in django-stubs indicated that the type of the
`from_field` argument to `ModelAdmin.get_object` should be `None`. In
fact, `None` is the default value of that argument. If the argument is
not `None`, [it is passed to a model's `_meta.get_field` method][impl], which
takes an argument of type `Union[Callable[..., Any], str`.

[impl]: https://github.com/django/django/blob/ac5cc6cf01463d90aa333d5f6f046c311019827b/django/contrib/admin/options.py#L767

* Fix formatting
2022-01-08 10:48:29 +03:00
Tom CarrickandGitHub 118f50307c Allow expressions in UniqueConstraint (#806)
* Allow expressions in UniqueConstraint

* Use ellipsis

* And for fields
2022-01-06 12:07:24 +03:00
AbhyudaiandGitHub 3761c16c51 Change return type of queryset.bulk_update to int (#683)
- the change was made in the commit https://github.com/django/django/commit/cd124295d882e13cff556fdeb78e6278d10ac6d5.
2022-01-05 18:42:47 +03:00
Carl Johan HambroandGitHub 49bed6c28d Fix type for templatetag (#801) 2021-12-31 11:56:10 +03:00
Gabriel AugendreandGitHub 3b02222beb Update syndication Feed class (#800)
* Update syndication Feed class

* Fix typing
2021-12-30 16:33:29 +03:00
Cory DolphinandGitHub 9483865284 Make geos.GEOSGeometryBase.equals_exact accept float (#796) 2021-12-29 11:16:16 +03:00
Gabriel AugendreandGitHub 1834242e46 Fix Feed.get_object signature (#798)
get_object's default implementation returns None but subclasses
are allowed to override this method and make it return anything.

The returned object would then be passed to other methods
to publish different data for different URL parameters.

https://docs.djangoproject.com/en/4.0/ref/contrib/syndication/
2021-12-29 11:07:43 +03:00
w0rpandGitHub 4a0dd04611 Set types for on_delete functions (#772)
Set types for on_delete functions so they can be provided as values to
the on_delete attribute of ForeignKey in Pyright's strict mode.
2021-12-17 22:20:01 +03:00
Nikita SobolevandGitHub b50a9077f8 Adds django@4.0 support (#786)
* Adds django@4.0 support

* Fixes CI

* Fixes CI

* Ignore new error for django4.0

* Fixes
2021-12-16 21:51:46 +03:00
Chris BeavenandGitHub 1219d62b6a Add Model._base_manager (#776) 2021-12-15 09:08:45 +03:00
Chris BeavenandGitHub daf6c659f0 Update autoreload to Django 3.2 (#775)
* Update autoreload stub to Django 3.2

* Fix some subclass return types

* types for watchmanreloader attributes

* Don't reference an redundant attribute in WatchmanReloader
2021-12-15 09:06:32 +03:00
w0rpandGitHub 059471101c Fix the get_field type for Pyright (#773)
This PR fixes the type of get_field so it won't report errors in
Pyright's strictest type checking mode.
2021-12-13 20:05:23 +03:00
Vadim SafonovandGitHub ccbbf86d0e Update signature for Django 3.1 Paginator (#770) 2021-12-09 22:35:32 +03:00
Chris BeavenandGitHub 69d4b1a86d More accurate template.Parser parse_until type (#769) 2021-12-09 11:26:26 +03:00
Marti RaudseppandGitHub 6436a10d5a Add more precise RunSQL, RunPython migration hints (#768) 2021-12-08 15:11:35 +03:00
Marti RaudseppandGitHub 79d34d6f46 Add ValidationError type hints (#767) 2021-12-08 15:09:20 +03:00
Kevin MarshandGitHub e5361f1e04 Fix QuerySet.create and Manager.create annotation since it doesn't accept *args (only **kwargs) (#762) 2021-11-30 18:37:54 +03:00
Stanislav MikhailovandGitHub 593d04d6e9 Fixed the types in ManyToManyField according to their definition in Django. (#758) 2021-11-24 01:13:45 +03:00
Sigurd LjødalandGitHub a57ae4fc76 Fix BaseConnectionWrapper.execute_wrapper (#752)
This is a context manager, not an iterator.

Currently mypy will complain if it's used as documented.
2021-11-15 18:14:42 +03:00
David CainandGitHub 331042d1c7 Add signature for Django 3.2 TimestampSigner (#751)
Django 3.2 introduced two new methods: `sign_object` and
`unsign_object` which can sign/unsign "complex data structures" such as
lists, tuples, dictionaries:

https://docs.djangoproject.com/en/3.2/topics/signing/#django.core.signing.TimestampSigner

Because the methods take an arbitrary serializer (a JSON serializer by
default, but not guaranteed), we cannot be sure of the type of `obj`.
2021-11-13 22:56:27 +03:00
Avery Fischer (biggerfisch)andGitHub b5c20100ff Update MigrationExecutor stubs to use Sequence (#749)
There is no need for a specific List type here, using a higher type
works fine and allows more working code to pass type-checking.
2021-11-12 20:10:24 +03:00
Petter FribergandGitHub 48aaf3d2ac Implement stubs for views.decorators.common.no_append_slash (#743) 2021-11-01 18:04:58 +03:00
Chris BeavenandGitHub 640553dcd7 Fix boundfield method parameters (#741) 2021-10-26 14:34:08 +03:00
Yukio MizutaandGitHub 95060b54c2 Update send_mail recipient_list type from List[str] to Sequence[str] (#740) 2021-10-22 21:51:57 +03:00
Simon CharetteandGitHub 09c3dc894b Adjust django.core.signing.dumps and loads key type. (#739)
An optional key can be provided to these functions.
2021-10-22 21:02:01 +03:00
andGitHub 9482f2f81c fix django.contrib.auth.models.Group.natural_key no return type (#724) 2021-10-19 15:03:53 +03:00
Brian HelbaandGitHub 676750e090 Add a definition for Storage.get_alternative_name (#732)
See: https://github.com/django/django/blob/f5802a21c401b92764a9f3e2886144f3c5d77573/django/core/files/storage.py#L65
2021-10-19 14:53:22 +03:00
Brian HelbaandGitHub 7c87c720ad Correct the type of FileField.storage (#731)
* Correct the type of FileField.storage

This instance property can't be a callable. Although the FileField constructor
allows a callable, it is immediately resolved to an instance of Storage.
See: https://github.com/django/django/blob/f5802a21c401b92764a9f3e2886144f3c5d77573/django/db/models/fields/files.py#L231-L235

* Correct the type of FieldFile.storage

This instance property is copied directly from `FileField.storage` and should be
the same type.
See: https://github.com/django/django/blob/f5802a21c401b92764a9f3e2886144f3c5d77573/django/db/models/fields/files.py#L21
2021-10-19 14:40:17 +03:00
Terence HonlesandGitHub fb12560981 update all path related operations to have more accurate types (#713) 2021-09-11 22:41:16 +03:00
Terence HonlesandGitHub 799b41fe47 fix typing on HttpResponse and StreamingHttpResponse (#712)
While the documentation for `HttpResponse` and `StreamingHttpResponse`
*says* `content` and `streaming_content` should be bytestrings [1] or an
iterable of bytestrings respectively [2], this is not what the API
supports [3] [4] and there are tests which make sure the API supports
more than bytestrings [5] [6] [etc]. Before assigning `content` or
`streaming_content` the code paths will call  `self.make_bytes` to
coerce the value to bytes.

[1]: https://github.com/django/django/blob/ecf87ad513fd8af6e4a6093ed918723a7d88d5ca/django/http/response.py#L324-L327
[2]: https://github.com/django/django/blob/0a28b42b1510b8093a90718bafd7627ed67fa13b/django/http/response.py#L395-L399
[3]: https://github.com/django/django/blob/ecf87ad513fd8af6e4a6093ed918723a7d88d5ca/django/http/response.py#L342-L362
[4]: https://github.com/django/django/blob/0a28b42b1510b8093a90718bafd7627ed67fa13b/django/http/response.py#L415-L427
[5]: https://github.com/django/django/blob/0a28b42b1510b8093a90718bafd7627ed67fa13b/tests/cache/tests.py#L2250
[6]: https://github.com/django/django/blob/0a28b42b1510b8093a90718bafd7627ed67fa13b/tests/i18n/urls.py#L8
2021-09-10 23:18:20 +03:00
Terence HonlesandGitHub fb4d20475b add HashedFilesMixin.url argument force (#714) 2021-09-10 10:02:48 +03:00
CraigandGitHub a1f3712c43 Add SmallAutoField (#710)
* Add SmallAutoField

* Test SmallAutoField presents as int
2021-09-09 15:58:03 +03:00
PIG208andGitHub 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
Tim NyborgandGitHub 44f7c25a4e extend ProtectedError and RestrictedError stubs (#682)
types for their properties
2021-08-03 11:13:15 +03:00
AbhyudaiandGitHub 695a7d71a7 Update type of BinaryField to include memoryview as well (#686) 2021-08-01 11:10:15 +03:00
Richard XiaandGitHub 08a662ecb1 Change PasswordResetForm.get_users() to return Iterable, not Iterator. (#678)
This matches the actual implementation in Django, where it only attempts
to use the result of get_users() in a for loop, which allows for any
Iterable, and it provides a more flexible and idiomatic API for users
who subclass PasswordResetForm.
2021-07-29 12:35:28 +03:00
Richard XiaandGitHub 0d7c32f38e Change PasswordResetForm.save() to accept HttpRequest, not WSGIRequest. (#679) 2021-07-29 12:26:06 +03:00
Michael WilliamsonandGitHub 51183231e0 Add @display to django.contrib.admin (#677)
The `display` decorator is defined in `django.contrib.admin.decorators`, but
isn't included in `django.contrib.admin`, which is how the Django docs describe
its usage.
2021-07-27 16:31:41 +03:00
snmishraandGitHub d29dacd64b Add accepts method stub in HttpRequest (#676)
* Add accepts method to HttpRequest stubs

The accepts method (and dependencies) was missing in the stub for HttpRequest

* Change accepted_types to return correct type

* Fix Black formatting

* Add annotation for MediaType __init__ args
2021-07-25 18:53:37 +03:00
snmishraandGitHub ee51aa4bf8 Add datetime to DateTimeField (#675)
* Add datetime to set_type of DateTimeField

`DateTimeField` was missing `datetime` as a valid set type. But Django clearly accepts `datetime`.

* Fix test for DateTimeField type change

datetime is now a valid set type for DateTimeField
2021-07-25 13:06:22 +03:00
Seth YastrovandGitHub cfd69c0acc QuerySet.annotate improvements (#398)
* QuerySet.annotate returns self-type. Attribute access falls back to Any.

- QuerySets that have an annotated model do not report errors during .filter() when called with invalid fields.
- QuerySets that have an annotated model return ordinary dict rather than TypedDict for .values()
- QuerySets that have an annotated model return Any rather than typed Tuple for .values_list()

* Fix .annotate so it reuses existing annotated types. Fixes error in typechecking Django testsuite.

* Fix self-typecheck error

* Fix flake8

* Fix case of .values/.values_list before .annotate.

* Extra ignores for Django 2.2 tests (false positives due to tests assuming QuerySet.first() won't return None)

Fix mypy self-check.

* More tests + more precise typing in case annotate called before values_list.

Cleanup tests.

* Test and fix annotate in combination with values/values_list with no params.

* Remove line that does nothing :)

* Formatting fixes

* Address code review

* Fix quoting in tests after mypy changed things

* Use Final

* Use typing_extensions.Final

* Fixes after ValuesQuerySet -> _ValuesQuerySet refactor. Still not passing tests yet.

* Fix inheritance of _ValuesQuerySet and remove unneeded type ignores.

This allows the test
"annotate_values_or_values_list_before_or_after_annotate_broadens_type"
to pass.

* Make it possible to annotate user code with "annotated models", using PEP 583 Annotated type.

* Add docs

* Make QuerySet[_T] an external alias to _QuerySet[_T, _T].

This currently has the drawback that error messages display the internal type _QuerySet, with both type arguments.

See also discussion on #661 and #608.

Fixes #635: QuerySet methods on Managers (like .all()) now return QuerySets rather than Managers.

Address code review by @sobolevn.

* Support passing TypedDicts to WithAnnotations

* Add an example of an error to README regarding WithAnnotations + TypedDict.

* Fix runtime behavior of ValuesQuerySet alias (you can't extend Any, for example).

Fix some edge case with from_queryset after QuerySet changed to be an
alias to _QuerySet. Can't make a minimal test case as this only occurred
on a large internal codebase.

* Fix issue when using from_queryset in some cases when having an argument with a type annotation on the QuerySet.

The mypy docstring on anal_type says not to call defer() after it.
2021-07-23 16:15:15 +03:00
Tim NyborgandGitHub c69e720dd8 Replace accepts expression as string (#671)
Fixes #503
2021-07-18 15:04:27 +03:00
Tim NyborgandGitHub 2a9410f3b1 widen type of make_password and get_hasher parameters (#670)
* widen type of make_password's hasher

make_password will accept a subclass of BasePasswordHasher as a hasher

* widen get_hasher's algorithm type

get_hasher will accept (and immediately return) a BasePasswordHasher
2021-07-18 15:01:36 +03:00
Abhishek ChaudharyandGitHub 446589e133 fix(BaseCache): corrected return type of get_many func (#666)
* fix(BaseCache): corrected return type of get_many func

* fix(basecache): made required changes
2021-07-05 14:44:04 +03:00
Nikita SobolevandGitHub d5e45db79b Better linting config (#664)
* Better linting config

* Applies isort on django-stubs, only style changes

* Fixes black and isort compat
2021-07-04 16:16:43 +03:00
Nikita SobolevandGitHub 552f2ffc0c Adds more rules to mypy config, related #662 (#663)
* Adds more rules to mypy config, related #662

* Removes plugin.ini for mypy settings

* Fixes build
2021-07-04 15:41:51 +03:00
horptoandGitHub d9c63f5e71 fix CursorWrapper iter method (#628) 2021-07-04 15:11:21 +03:00
Michael AquilinaandGitHub 008dcdbcb6 chore: remove excess # type: ignore comments in _ValuesQuerySet (#662) 2021-07-04 14:53:28 +03:00