Commit Graph

768 Commits

Author SHA1 Message Date
Avery Fischer (biggerfisch)
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 Friberg
48aaf3d2ac Implement stubs for views.decorators.common.no_append_slash (#743) 2021-11-01 18:04:58 +03:00
Chris Beaven
640553dcd7 Fix boundfield method parameters (#741) 2021-10-26 14:34:08 +03:00
Yukio Mizuta
95060b54c2 Update send_mail recipient_list type from List[str] to Sequence[str] (#740) 2021-10-22 21:51:57 +03:00
Simon Charette
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
9482f2f81c fix django.contrib.auth.models.Group.natural_key no return type (#724) 2021-10-19 15:03:53 +03:00
Brian Helba
676750e090 Add a definition for Storage.get_alternative_name (#732)
See: f5802a21c4/django/core/files/storage.py (L65)
2021-10-19 14:53:22 +03:00
Brian Helba
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: f5802a21c4/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: f5802a21c4/django/db/models/fields/files.py (L21)
2021-10-19 14:40:17 +03:00
Rob Percival
9938378e94 Make AddRelatedManagers look for "objects" on parent model (#730)
* Add failing test for relation to model inheriting `objects`

Fails with:
```
pytest_mypy_plugins.utils.TypecheckAssertionError: Invalid output:
Expected:
  main:2: note: Revealed type is "myapp.models.MyUser*"
  main:3: note: Revealed type is "myapp.models.MyUser*"
  <45 (diff)
  <45 (diff)
Actual:
  main:2: note: Revealed type is "myapp.models.MyUser*"
  main:3: note: Revealed type is "myapp.models.MyUser*"
  main:6: error: "MyUser" has no attribute "book_set" (diff)
  main:6: note: Revealed type is "Any"          (diff)
  main:7: error: "MyUser" has no attribute "article_set" (diff)
  main:7: note: Revealed type is "Any"          (diff)
```

* Make AddRelatedManagers look for "objects" on parent model

Previously, AddRelatedManagers would fail if a related model had inherited
its `objects` field from a parent class. This would result in missing
relation attributes. This is fixed by using `get()` instead of `names`;
the former searches the MRO for the symbol, whereas the latter only looks
for symbols declared directly on the class.
2021-10-19 14:31:14 +03:00
Nikita Sobolev
7ac33f3a28 Fixes CI (#734)
* Fixes CI

* Fixes CI

* Fixes CI
2021-10-19 14:10:25 +03:00
Terence Honles
fb12560981 update all path related operations to have more accurate types (#713) 2021-09-11 22:41:16 +03:00
Terence Honles
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]: ecf87ad513/django/http/response.py (L324-L327)
[2]: 0a28b42b15/django/http/response.py (L395-L399)
[3]: ecf87ad513/django/http/response.py (L342-L362)
[4]: 0a28b42b15/django/http/response.py (L415-L427)
[5]: 0a28b42b15/tests/cache/tests.py (L2250)
[6]: 0a28b42b15/tests/i18n/urls.py (L8)
2021-09-10 23:18:20 +03:00
Terence Honles
fb4d20475b add HashedFilesMixin.url argument force (#714) 2021-09-10 10:02:48 +03:00
Craig
a1f3712c43 Add SmallAutoField (#710)
* Add SmallAutoField

* Test SmallAutoField presents as int
2021-09-09 15:58:03 +03:00
sobolevn
372b1340a0 Version django-stubs-ext@0.3.1 release 2021-09-07 22:08:49 +03:00
Eero Ruohola
6424e33a74 Fix BaseModelForm not working with generic type parameter (#705)
Resolves: https://github.com/typeddjango/django-stubs/issues/703
2021-09-07 22:07:22 +03:00
Eero Ruohola
b6d3373c34 Add typing-extension as a direct dependency of django-stubs-ext (#707)
Needed, because `django-stubs-ext` generally has to specified as a
production dependency (to use the monkey patching). `django-stubs` does
have `typing-extensions` as a dependency, but it is often used only as a
dev dependency as it has not runtime functionality.

Resolves: https://github.com/typeddjango/django-stubs/issues/702
2021-09-07 12:01:21 +03:00
Nikita Sobolev
f98330356c Update bug.md 2021-09-04 20:10:23 +03:00
sobolevn
a33d8a9e59 Version 1.9.0 release 2021-09-04 11:54:02 +03:00
sobolevn
d6ccecdd73 Version 1.9.0 release 2021-09-04 11:33:39 +03:00
sobolevn
321284ac62 Version 1.9.0 release 2021-09-04 11:31:11 +03:00
sobolevn
a0f893ea3d Version django-stubs-ext@0.3.0 release 2021-09-04 11:30:30 +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:
75337a6050

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
Tim Nyborg
44f7c25a4e extend ProtectedError and RestrictedError stubs (#682)
types for their properties
2021-08-03 11:13:15 +03:00
Abhyudai
696f39b58c Remove assertions for mypy builtins (#685) 2021-08-01 11:14:13 +03:00
Abhyudai
01eecf901f Add tests for some queryset methods (#684) 2021-08-01 11:12:06 +03:00
Abhyudai
695a7d71a7 Update type of BinaryField to include memoryview as well (#686) 2021-08-01 11:10:15 +03:00
Seth Yastrov
8da8ab4862 Fix/673/from queryset then custom qs method (#680)
* Fix `MyModel.objects.filter(...).my_method()`

* Fix regression: `MyModel.objects.filter(...).my_method()` no longer worked when using from_queryset

This also fixes the self-type of the copied-over methods of the manager generated by from_queryset.
Previously it was not parameterized by the model class, but used Any.

The handling of unbound types is not tested here as I have not been able to
find a way to create a test case for it. It has been manually tested
against an internal codebase.

* Remove unneeded defer.
2021-07-30 01:01:39 +03:00
Richard Xia
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 Xia
0d7c32f38e Change PasswordResetForm.save() to accept HttpRequest, not WSGIRequest. (#679) 2021-07-29 12:26:06 +03:00
Michael Williamson
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
snmishra
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
snmishra
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
github-actions[bot]
ee9c0d4a32 Fixes by misspell-fixer (#674)
Co-authored-by: sobolevn <sobolevn@users.noreply.github.com>
2021-07-24 10:48:48 +03:00
Seth Yastrov
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 Nyborg
c69e720dd8 Replace accepts expression as string (#671)
Fixes #503
2021-07-18 15:04:27 +03:00
Tim Nyborg
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
Petter Friberg
cc5d363cfa Add end-of-file-fixer hook to pre-commit (#668) 2021-07-12 00:48:36 +03:00
Abhishek Chaudhary
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 Sobolev
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 Sobolev
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
horpto
d9c63f5e71 fix CursorWrapper iter method (#628) 2021-07-04 15:11:21 +03:00
Michael Aquilina
008dcdbcb6 chore: remove excess # type: ignore comments in _ValuesQuerySet (#662) 2021-07-04 14:53:28 +03:00
Michael Aquilina
5c3ce171b2 Add more method signatures for _ValuesQuerySet (#661) 2021-07-03 20:12:05 +03:00
Michael Aquilina
13c620f572 chore: remove unused class stubs from query.pyi (#660) 2021-07-03 16:14:16 +03:00
Michael Aquilina
ded66f6937 Add distinct, order_by and all method signatures for _ValuesQuerySet (#657) 2021-07-03 16:00:58 +03:00
David Szotten
739b1711a9 Use Sequence instead of List for path param (#659)
Unlike `List`, which is invariant, `Sequence` is covariant, which lets
`path` accept lists of subsets of the `Union` as well.

I believe this is safe, as django doesn't mutate this input. I found
[this
comment](https://github.com/python/mypy/issues/3351#issuecomment-300447832)
helpful
2021-07-03 13:46:29 +03:00
darius-blink
cf6952c9df Fix type of MigrationLoader.applied_migrations (#656)
Co-authored-by: Darius Marian <marian.darius98@gmail.com>
2021-06-30 12:23:48 +03:00