Commit Graph

921 Commits

Author SHA1 Message Date
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:
03eec9ff6c/django/db/models/sql/where.py (L271-L281)
03eec9ff6c/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:
03eec9ff6c/django/template/loaders/app_directories.py
03eec9ff6c/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:
863aa7541d/django/views/static.py (L17-L53)
863aa7541d/django/contrib/staticfiles/views.py (L15-L39)
863aa7541d/django/contrib/staticfiles/handlers.py (L48-L50)
863aa7541d/django/test/testcases.py (L1680-L1687)

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2022-07-04 23:46:53 +03:00
Sigurd Ljødal
ae30525404 Fix type stubs for EmptyManager (#1039)
This should be parametrized based on the passed model. This also removes
the need for overriding the get_queryset method.
2022-07-04 12:43:58 +03:00
Petter Friberg
2a6f4647f0 Populate model argument for dynamically created managers (#1033)
* Populate model for dynamically created managers

* fixup! Populate model for dynamically created managers
2022-06-30 10:25:29 +03:00
Sigurd Ljødal
84eff75566 Resolve all queryset methods on managers as attributes (#1028)
* Add test case reproducing Sequence name not defined issue

* Resolve all manager methods as attribute

This changes to logic for resolving methods from the base QuerySet class
on managers from copying the methods to use the attribute approach
that's already used for methods from custom querysets. This resolves the
phantom type errors that stem from the copying.

* Disable cache in test case

Make sure the test will fail regardless of which mypy.ini file is being using.

Co-authored-by: Petter Friberg <petter@5monkeys.se>

* Update comments related to copying methods

* Use a predefined list of manager methods to update

The list of manager methods that returns a queryset, and thus need to
have it's return type changed, is small and well defined. Using a
predefined list of methods rather than trying to detect these at runtime
makes the code much more readable and probably faster as well.

Also add `extra()` to the methods tested in
from_queryset_includes_methods_returning_queryset, and sort the methods
alphabetically.

* Revert changes in .github/workflows/tests.yml

With cache_disable: true on the test case this is no longer needed to
reproduce the bug.

* Remove unsued imports and change type of constant

 - Remove unused imports left behind
 - Change MANAGER_METHODS_RETURNING_QUERYSET to Final[FrozenSet[str]]

* Import Final from typing_extensions

Was added in 3.8, we still support 3.7

* Sort imports properly

* Remove explicit typing of final frozenset

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>

* Add comment for test case

* Fix typo

* Rename variable

Co-authored-by: Petter Friberg <petter@5monkeys.se>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-06-30 10:19:33 +03:00
David Smith
f8cc99ca3b Improved return type of render_to_string(). (#1036) 2022-06-30 10:16:07 +03:00
dependabot[bot]
c27b38d6b9 Bump requests from 2.28.0 to 2.28.1 (#1035)
Bumps [requests](https://github.com/psf/requests) from 2.28.0 to 2.28.1.
- [Release notes](https://github.com/psf/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md)
- [Commits](https://github.com/psf/requests/compare/v2.28.0...v2.28.1)

---
updated-dependencies:
- dependency-name: requests
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-30 10:14:45 +03:00
Anders Kaseorg
214b0c7439 Support cursor.execute(psycopg2.sql.Composable) (#1029)
In addition to str, PostgreSQL cursors accept the
psycopg2.sql.Composable type, which is useful for guarding against SQL
injections when building raw queries that can’t be parameterized in
the normal way (e.g. interpolating identifiers).

In order to avoid reintroducing a dependency on psycopg2, we define a
Protocol that matches psycopg2.sql.Composable.

Documentation: https://www.psycopg.org/docs/sql.html
Related: https://github.com/python/typeshed/pull/7494

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2022-06-28 23:44:20 +03:00
Nikita Sobolev
33d4dc7dae Fix logger type in all modules (#1031)
* Fix `logger` type in all modules

* Fix CI
2022-06-28 23:25:50 +03:00
dependabot[bot]
fe2d2287a1 Bump black from 22.3.0 to 22.6.0 (#1027)
Bumps [black](https://github.com/psf/black) from 22.3.0 to 22.6.0.
- [Release notes](https://github.com/psf/black/releases)
- [Changelog](https://github.com/psf/black/blob/main/CHANGES.md)
- [Commits](https://github.com/psf/black/compare/22.3.0...22.6.0)

---
updated-dependencies:
- dependency-name: black
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-28 09:42:09 +03:00
David Smith
926661ab4a Improved type of template.loader.get_template() (#1011)
* Improved type of template.loader.get_template()

* Removed Optional from return type.

* Edits.
2022-06-27 00:48:10 +03:00
Sigurd Ljødal
1a29ad4f97 Fix nullability of blank charfields in values and values_list (#1020)
Char fields with blank=True set should not be considered nullable in the
context of values() and values_list() querysets.

I'm also not a huge fan of the way these fields are made optional in the
constructur to the model classes, it feels like it would be better to
mark the arguments as having a default value, rather than allow sending
in None, but I'd rather keep this fix small and look at the overall
problem at a later point.
2022-06-25 14:37:25 +03:00
Jakub Hrabec
dd0fe02367 Add missing type for TestCase.captureOnCommitCallbacks (#1016)
* add missing type for TestCase.captureOnCommitCallbacks

* change default value
2022-06-25 13:41:29 +03:00
David Smith
44157a4b03 BaseContext.__copy__ (#1012)
* Improved BaseContext.__copy__()

* Update django-stubs/template/context.pyi

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>

* Updated __copy__ to use private name.

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-06-25 11:57:04 +03:00
Jakub Hrabec
c020349f2e Update RunSQL type to include parametrized sql (#1015)
* update RunSQL type to include parametrized sql

* fix Black formatting
2022-06-24 10:08:17 +03:00
w0rp
644052148a Set generic type of SimpleCookie (#1018)
Pyright complains about `response.cookies` because the generic type isn't known. `str` may or may not be the correct type to use here. Something should be set here.
2022-06-23 13:52:31 +03:00
sobolevn
f4407155a5 Do not generate release notes for django-stubs-ext 2022-06-17 18:14:44 +03:00
sobolevn
d6a9a4ef03 Fixing release pipeline 2022-06-17 18:09:00 +03:00
sobolevn
9a23ff864b Fixing release pipeline 2022-06-17 17:54:02 +03:00
sobolevn
4ea9b874f5 Add explicit test for .from_quertset Any fallback 2022-06-17 17:30:27 +03:00
Petter Friberg
023106fe45 Emit error and set fallback type for managers that can't be resolved (#999)
* Emit error and set fallback type for managers that can't be resolved

* fixup! Emit error and set fallback type for managers that can't be resolved
2022-06-17 17:19:42 +03:00
sobolevn
719cd3a6bc Fix release pipeline 2022-06-17 17:18:15 +03:00
sobolevn
4cf3b445bd Fix release pipeline 2022-06-17 17:15:28 +03:00
sobolevn
f4378112bb Release django-stubs and django-stubs-ext 2022-06-17 17:02:26 +03:00
Adam Birds
86c007d83f Add Feed to monkeypatch to fix generic issue. (#1002)
Fixes #1001
2022-06-17 16:39:11 +03:00
Nikita Sobolev
633030585d Update README.md 2022-06-17 16:33:12 +03:00
Petter Friberg
8d8b8cd1fc Set type of default django.core.cache.cache to BaseCache (#998)
* Set type of default `django.core.cache` to `BaseCache`

- The previous type `ConnectionProxy` is just a proxy class, thus
  revealing `Any` for _all_ cache methods

* fixup! Set type of default `django.core.cache` to `BaseCache`
2022-06-16 23:33:37 +03:00
Marti Raudsepp
e45ecd633e Improve hints in migration Operation class (#996) 2022-06-16 09:15:23 +03:00
Aleksander Vognild Burkow
9044a354cb Add fallback related manager in final iteration of AddRelatedManagers (#993)
If a django model has a Manager class that cannot be resolved statically
(if it is generated in a way where we cannot import it, like `objects =
my_manager_factory()`), we fallback to the default related manager, so
you at least get a base level of working type checking.
2022-06-15 18:50:53 +03:00
sterliakov
32e13c37a6 Fix manager types scope (#991)
* Fix manager types scope

* Restore incremental mode and mention in developer docs

* Separate dev mypy config and regular one

* Document config files usage
2022-06-14 20:30:13 +03:00
Adam Johnson
ae5b1a4edf Improve admin filter lookups() return type (#992) 2022-06-13 18:45:55 +03:00
dependabot[bot]
6e84c103af Bump actions/setup-python from 3 to 4 (#989)
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 3 to 4.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-11 09:43:41 +03:00
dependabot[bot]
b6cd673e4c Bump requests from 2.27.1 to 2.28.0 (#990)
Bumps [requests](https://github.com/psf/requests) from 2.27.1 to 2.28.0.
- [Release notes](https://github.com/psf/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md)
- [Commits](https://github.com/psf/requests/compare/v2.27.1...v2.28.0)

---
updated-dependencies:
- dependency-name: requests
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-11 09:43:33 +03:00
Terence Honles
1ce113d743 Enable GitHub auto generated release notes for GitHub releases (#988) 2022-06-11 09:43:24 +03:00
Zac Miller
f7ccf04082 Remove coreapi from requirements.txt (#987) 2022-06-09 00:04:16 +03:00
Terence Honles
a526ba75be remove unneeded submodule (removed in #485) (#982) 2022-06-07 23:07:15 +03:00
Adam Johnson
13c09921f8 Improve admin filter types (#984) 2022-06-07 12:29:44 +03:00
dependabot[bot]
195aaad1fe Bump mypy from 0.960 to 0.961 (#983)
Bumps [mypy](https://github.com/python/mypy) from 0.960 to 0.961.
- [Release notes](https://github.com/python/mypy/releases)
- [Commits](https://github.com/python/mypy/compare/v0.960...v0.961)

---
updated-dependencies:
- dependency-name: mypy
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-07 12:23:20 +03:00
Terence Honles
42321cabe6 Add GitHub release action to upload to PyPI & create GitHub release (#980)
* Add GitHub release action to upload to PyPI & create GitHub release

* Update .github/workflows/release.yml

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-06-07 12:23:03 +03:00
Anders Kaseorg
24a3b22c60 Move mypy version upper bound to a [compatible-mypy] extra (#979)
* Move mypy version upper bound to a [compatible-mypy] extra

Due to a bug in mypy 0.940 (#870), we made two changes in #871:

• pinned mypy==0.931 in requirements.txt (for running our tests);
• bounded mypy<0.940 in setup.py (for downstream users).

After the mypy bug was quickly fixed upstream in 0.941, our setup.py
bound has been repeatedly raised but not removed (#886, #939, #973).
The only changes in those commits have been to the precise wording of
error messages expected in our tests.  Those wording changes don’t
impact compatibility for downstream users, so it should be safe to go
back to allowing them to upgrade mypy independently.

Since mypy doesn’t yet guarantee backwards compatibility in the plugin
API (although in practice it has rarely been an issue), add a
django-stubs[compatible-mypy] extra for users who prefer a known-good
version of mypy even if it’s a little out of date.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>

* Update setup.py

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-06-05 00:08:00 +03:00
Daniel Hahler
43b082850c Fix BaseModelFormSet.save_m2m: accept self (#970)
* Fix BaseModelFormSet.save_m2m: accept `self`

Before it would result in the following when calling it:

> Attribute function "save_m2m" with type "Callable[[], None]" does not accept self argument  [misc]

* fixup! Fix BaseModelFormSet.save_m2m: accept `self`
2022-05-27 13:42:45 +03:00
Ceesjan Luiten
42d8e18bf8 Support content attribute for a Testing Response. (#968)
`content` is a documented attribute of a testing response which isn't part
of the parent HttpResponseBase:

https://docs.djangoproject.com/en/4.0/topics/testing/tools/#testing-responses
2022-05-26 13:17:22 +03:00
Alex Dutton
0a13d2c653 Fix AlterModelManagers managers annotation to be [(str, Manager), ...] (#966)
Django generates AlterModelManagers with Sequence[Tuple[str, Manager]]
arguments — not Sequence[Manager] — as shown by their tests[^1].

[^1]: https://github.com/django/django/blob/4.0.4/tests/migrations/test_operations.py#L3792-L3799

Closes #965.
2022-05-26 12:56:54 +03:00
Allex
fc6fae192e Fix false positive ModelAdmin.list_display_links=None (#964)
* Fix false positive ModelAdmin.list_display_links=None

list_display_links can be set to None to not generate any links in the list display.

https://docs.djangoproject.com/en/4.0/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display_links

* Update django-stubs/contrib/admin/options.pyi

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-05-26 01:27:11 +03:00
Damian Zaremba
2351051ef1 Upgrade mypy support to 0.960 (#973)
- Updates test_model_field_classes_from_existing_locations to account
  for the behaviour change in https://github.com/python/mypy/pull/12663
- Bumps the version of django-stubs for a new release
2022-05-26 01:20:44 +03:00
Maksim Kurnikov
4a90ad9edc bump version to 1.11.0 (#961) 2022-05-24 11:22:43 +02:00
Mattias Jakobsson
e221f0e053 Sync django.contrib.gis.gdal with upstream (#956) 2022-05-14 08:53:27 +03:00
henribru
8fe2bd4b9b Support passing extra classes to monkeypatch (#953)
* Support passing extra classes to monkeypatch

Closes https://github.com/typeddjango/django-stubs/issues/946#issuecomment-1122895190

* Move extra classes into separate test

* Avoid mutable default

* Fix protocol arguments
2022-05-12 20:14:59 +03:00
Sigurd Ljødal
ccef6779ad Fix type for related fields in values_list querysets (#955)
When fetching a related field in a values_list queryset Django will
return the object primary key, not model instances as was previously
what the mypy plugin assumed.
2022-05-12 09:14:17 +03:00
Sigurd Ljødal
724442b241 Fix type stubs for OuterRef (#952)
* Fix error when nesting OuterRef expressions

OuterRef(OuterRef("my_field")) is a valid expression in nested
subqueries. Mypy would complain that OuterRef was an incompatible type
because OuterRef is typed to only accept str.

* Only fix for OuterRef

* OuterRef is not guaranteed to be resolved to ResolvedOuterRef
2022-05-10 20:44:49 +03:00
Sigurd Ljødal
7d84e5473a Fix type of min_value and max_value on DecimalField (#951)
* Fix type of min_value and max_value on DecimalField

These should at the very least allow Decimals. Technically you can send
in anything that's comparable to a Decimal, but I'm not sure if it makes
sense to allow floats. Could allow both ints and Decimals I guess?

* Allow ints and floats as well

* Update django-stubs/forms/fields.pyi

* Update django-stubs/forms/fields.pyi

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-05-10 20:43:49 +03:00