Commit Graph

850 Commits

Author SHA1 Message Date
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
Seth Yastrov
0c3252fb97 Check whether reported issues actually fails currently (#653) 2021-06-28 13:23:20 +03:00
Seth Yastrov
f9317c7679 Rename ValuesQuerySet -> _ValuesQuerySet and remove _BaseQuerySet. Ma… (#654)
* Rename ValuesQuerySet -> _ValuesQuerySet and remove _BaseQuerySet. Make a public alias called ValuesQuerySet in django_stubs_ext.

* Update tests
2021-06-28 13:23:00 +03:00
Seth Yastrov
29e971ed9d Allow setting AutoFields to None (#634) 2021-06-28 03:23:54 +03:00
Daniel Hahler
a00563cfa4 [WIP/RFC] Revisit patching of mypy builtins (reveal_{type,locals}) (#615)
* Revisit patching of mypy builtins (reveal_{type,locals})

Fixes https://github.com/typeddjango/django-stubs/issues/609
Reverts ee58b18f15

* Create test_patching.yml

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2021-06-25 16:56:21 +03:00
sobolevn
159a0e4790 Adds docs for how Field access works 2021-06-23 13:44:06 +03:00
Nikita Sobolev
eb702384a8 Improves edit.py and its forms (#648)
* Improves edit.py and its forms

* Adds tests
2021-06-16 11:25:57 +03:00
Chris Beaven
acfe0ce820 Patch detail and list generic view base classes (#642)
Similar to the already patched `FormMixin`, the detail and list generic view classes are also missing __class_getitem__ and choke when you try to use their generics.
2021-06-16 10:32:47 +03:00
Patrick Gingras
f182b39c91 Copy decorated queryset methods to manager too (#646)
* copy decorated queryset methods to manager too

* added test for from_manager with decorated queryset methods
2021-06-16 10:15:32 +03:00
Anton Agestam
96ae17f4a7 Add missing queryset annotations (#644) 2021-06-15 11:51:13 +03:00
Cesar Canassa
397e3f3dac Adds support for pyproject.toml files (#639)
* Adds support for pyproject.toml files

Since mypy 0.900 the pyproject.toml files are supported.

This PR adds a support for it. It searchs for a `tool.django-stubs` section. This is an example configuration:

```
[tool.django-stubs]
django_settings_module = "config.settings.local"
```

Fixes #638

* Added TOML tests

* Use textwrap.dedent instead of trying to manually replace spaces
2021-06-15 01:50:31 +03:00
Maarten ter Huurne
8c387e85fe Allow Collection for 'fields' and 'exclude' of form model helpers (#637) (#640)
* Allow Collection for 'fields' and 'exclude' of form model helpers (#637)

There are several functions and classes in `django.forms.models` that
take a `fields` or `exclude` argument. Previously, `Sequence` was used
to annotate these, but the code of Django (I checked version 3.2.4)
doesn't require `__getitem__()` to be implemented, so requiring
`Collection` instead is sufficient.

The practical advantage of requiring `Collection` is that a set, such
as the key set of a dictionary, can be passed without first having to
convert it to a list or tuple.

* Pin mypy to below version 0.900

* Remove Callable for 'fields' and 'exclude' of form model helpers

I cannot find any support for callables for these two arguments in
the code or in the documentation.

* Update setup.py

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2021-06-12 01:21:42 +03:00
Cesar Canassa
77f9926ce1 fix tests for mypy 0.900 (#641) 2021-06-12 01:05:46 +03:00
Nikita Sobolev
47f1700a8b Update test.yml 2021-06-05 23:46:55 +03:00
Seth Yastrov
48c0bf0713 get_language can sometimes return None (#633)
https://docs.djangoproject.com/en/3.2/ref/utils/#django.utils.translation.get_language
> Returns the currently selected language code. Returns None if translations are temporarily deactivated (by deactivate_all() or when None is passed to override()).
2021-06-04 16:02:08 +03:00
jonfoster
893ad6bb02 #629: Add HTTP response "streaming" attribute (#632)
Add the missing attribute django.http.response.StreamingHttpResponse.streaming .

This is actually done by moving the attribute from HttpResponse to the base class HttpResponseBase.

The real Django source code declares this attribute on HttpResponse and StreamingHttpResponse, however that's only because Django doesn't have type hints.  The right place for the type hint is on the base class HttpResponseBase, since all instances of that base class are actually instances of HttpResponse or StreamingHttpResponse or a subclass of those two classes.  So it's guaranteed that every HttpResponseBase instance has the attribute.

Fixes bug #629.
2021-06-03 21:25:25 +03:00
Abhishek Chaudhary
becb0c9605 fix(ResolverMatch): Added _func_path (#631)
* fix(ResolverMatch): Added _func_path

ResolverMatch class in Django contains _func_path variable and it will get initialized in init method whatever the condition, so it should be added in type stubs as well. https://github.com/django/django/blob/main/django/urls/resolvers.py#L48

* Update resolvers.pyi

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2021-06-03 13:57:16 +03:00
Paweł Markowski
9a95b98398 add concrete attr to field (#623) 2021-05-25 18:22:48 +03:00
Nikita Sobolev
e12a2d9aef Update README.md 2021-05-24 11:56:08 +03:00