Commit Graph

1013 Commits

Author SHA1 Message Date
github-actions[bot]
1c914abfa8 Auto-update pre-commit hooks (#1188)
Co-authored-by: sobolevn <sobolevn@users.noreply.github.com>
2022-10-11 09:56:01 +03:00
dependabot[bot]
994312672e Bump black from 22.8.0 to 22.10.0 (#1184)
Bumps [black](https://github.com/psf/black) from 22.8.0 to 22.10.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.8.0...22.10.0)

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

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-07 09:37:11 +03:00
dependabot[bot]
4235bf7585 Bump gitpython from 3.1.27 to 3.1.28 (#1185)
Bumps [gitpython](https://github.com/gitpython-developers/GitPython) from 3.1.27 to 3.1.28.
- [Release notes](https://github.com/gitpython-developers/GitPython/releases)
- [Changelog](https://github.com/gitpython-developers/GitPython/blob/main/CHANGES)
- [Commits](https://github.com/gitpython-developers/GitPython/compare/3.1.27...3.1.28)

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

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-07 09:37:03 +03:00
github-actions[bot]
1cc6ec39a6 Auto-update pre-commit hooks (#1186)
Co-authored-by: sobolevn <sobolevn@users.noreply.github.com>
2022-10-07 09:36:53 +03:00
Anders Kaseorg
41deee4ec6 Update utils.log.log_response type for Django 4.1 (#1183)
90cf963264

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

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2022-10-06 11:22:20 +03:00
PIG208
05dc579748 Add missing re-export for JSONObject. (#1182) 2022-10-06 08:43:05 +01:00
github-actions[bot]
3a2f806282 Auto-update pre-commit hooks (#1181)
Co-authored-by: sobolevn <sobolevn@users.noreply.github.com>
2022-10-05 12:55:39 +03:00
dependabot[bot]
4bdf385602 Bump mypy from 0.981 to 0.982 (#1180)
Bumps [mypy](https://github.com/python/mypy) from 0.981 to 0.982.
- [Release notes](https://github.com/python/mypy/releases)
- [Commits](https://github.com/python/mypy/compare/v0.981...v0.982)

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

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-10-04 11:13:05 +03:00
Sigurd Ljødal
dde0f2f876 Reparametrize managers without explicit type parameters (#1169)
* Reparametrize managers without explicit type parameters

This extracts the reparametrization logic from #1030 in addition to
removing the codepath that copied methods from querysets to managers.
That code path seems to not be needed with this change.

* Use typevars from parent instead of base

* Use typevars from parent manager instead of base manager

This removes warnings when subclassing from something other than the
base manager class, where the typevar has been restricted.

* Remove unused imports

* Fix failed test

* Only reparametrize if generics are omitted

* Fix docstring

* Add test with disallow_any_generics=True

* Add an FAQ section and document disallow_any_generics behaviour
2022-10-03 20:36:45 +03:00
Marti Raudsepp
946274bed8 Add UUIDField lookup types (#1178) 2022-10-02 13:48:37 +03:00
Marti Raudsepp
db14454199 Fix type of <fieldname>_id when using ForeignKey(to_field=) (#1176)
* Fix type of <fieldname>_id when using ForeignKey(to_field=)

Previously mypy_django_plugin would always use the field type of target
model's primary key, but `to_field` can refer to a different field type.

* Fixes

* More fixes
2022-09-30 10:05:57 +03:00
Sigurd Ljødal
5c616863dc Add SETTINGS_MODULE to Settings and LazySettings (#1175)
Add SETTINGS_MODULE as an attriute to the Settings and LazySettings
classes. This makes mypy aware of this attribute.

Fixes #1174
2022-09-30 10:03:54 +03:00
Petter Friberg
54d5835f66 Implement support for <QuerySet>.as_manager() (#1025)
* Implement support for `<QuerySet>.as_manager()`

* fixup! Implement support for `<QuerySet>.as_manager()`

* fixup! fixup! Implement support for `<QuerySet>.as_manager()`
2022-09-29 15:05:25 +03:00
Sigurd Ljødal
1f2e406972 Don't allow promise to be passed to ArrayField.name (#1171)
This was incorrectly changed in #1168, so reverting that change.
2022-09-28 16:34:43 +03:00
Marti Raudsepp
56f74f1940 Disallow passing bytes for field verbose_name (#1170)
`verbose_name` is intended to be a human-readable string, not binary.
2022-09-27 19:56:25 +03:00
Sigurd Ljødal
199a7f2707 Allow Promise to be passed to ArrayField.verbose_name (#1168)
* Allow Promise to be passed to ArrayField.verbose_name

* Remove bytes and allow Promise for name as well
2022-09-27 17:53:28 +03:00
Nikita Sobolev
93fa1d2e19 Update mypy to 0.981 (#1167)
* Update mypy to 0.981

* Fix plugin API

* Fix scripts

* Fix scripts

* Fix plugin
2022-09-27 11:55:36 +03:00
github-actions[bot]
bba51ce67d Auto-update pre-commit hooks (#1165)
Co-authored-by: sobolevn <sobolevn@users.noreply.github.com>
2022-09-26 09:17:41 +03:00
github-actions[bot]
f6a8c8dc8d Auto-update pre-commit hooks (#1164)
Co-authored-by: sobolevn <sobolevn@users.noreply.github.com>
2022-09-25 08:51:38 +03:00
Anders Kaseorg
9bd8aed1e1 Disable fallback to runtime types for Django settings (#1163)
This fallback to value.__class__ seems to be doing more harm than
good; see #312 and #1162.  Replace it with a clear error message that
suggests a way to fix the problem rather than incompletely papering
over it.

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

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2022-09-24 10:57:45 +03:00
Sigurd Ljødal
02999f3e86 Fix unresolved placeholder error during serialization (#1161)
This fixes an error that occured during state serialization. Completely
unsure how to reproduce this in a test but it resolves a long-standing
prolem in our project at work at least.
2022-09-23 21:35:23 +03:00
PIG208
3bc8278424 Fix paramters for ParallelTestSuite and RemoteTestRunner. (#1072)
* Fix paramters for ParallelTestSuite and RemoteTestRunner.

A new parameter `buffer` is added. `suites` is renamed to `subsuites`.

ParallelTestSuite:
2fac0a1808/django/test/runner.py (L468-L475)

RemoteTestRunner:
2fac0a1808/django/test/runner.py (L350)

`buffer` was added in f6713cda89,
`suites` was renamed in cb6c19749d.
Both of these changes were made in 4.1rc1.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Adjust types of attributes for runners.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2022-09-20 08:52:16 +03:00
Petter Friberg
6f9afd3cc9 Relax fields= arg for refresh_from_db to accept Sequence (#1156) 2022-09-19 23:14:08 +01:00
PIG208
d7326315b1 Improve stubs for runserver management command. (#1037)
This adds type annotation for `run`, `get_handler`, `inner_run` and
`server_cls`.

Source code:
03eec9ff6c/django/core/management/commands/runserver.py
2022-09-19 22:30:04 +03:00
PIG208
9a41aa63ba Broaden type annotation for verbose_name(_plural) to accept lazystr. (#1139)
* Broaden type annotation for verbose_name(_plural) to accept lazystr.

Fixes #1137.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Broaden type annotation for help_text to accept lazystr.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Broaden type annotation for ValidationError to accept lazystr.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Broaden type annotation for label to accept lazystr.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Add StrPromise and StrOrPromise aliases to django_stubs_ext.

We make StrPromise and StrOrPromise available via django_stubs_ext so
that conditional imports with TYPE_CHECKING is not required.
These aliases fall back to Promise or Union[str, Promise]
when not TYPE_CHECKING.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2022-09-19 17:01:44 +03:00
Petter Friberg
a2a3543198 Adjust choices= type variance for model fields (#1154)
Avoid getting stuck in an invariance pit. I don't think it makes sense
to mix two tuple with named group elements in same choices sequence(?).

This also changes the outermost container type to `Sequence` as e.g.
both `tuple` and `list` are supported.
2022-09-19 13:17:17 +03:00
github-actions[bot]
88793ee3f7 Auto-update pre-commit hooks (#1153) 2022-09-16 08:32:46 +01:00
Petter Friberg
b34ebe7553 Serialize RelatedManager attributes in cache (#1152) 2022-09-15 23:54:10 +03:00
Adam Johnson
29e2b65c8b Improve Flake8 config (#1149) 2022-09-09 17:16:22 +03:00
Yannik Rödel
abd0609f80 Add type and parameter fields to MediaType (#1103) 2022-09-09 14:48:24 +01:00
Adam Johnson
3c942483d4 Correct EmailMultiAlternatives.body (#1146) 2022-09-08 14:13:54 +03:00
dependabot[bot]
354a892ecc Bump pytest from 7.1.2 to 7.1.3 (#1144)
Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.1.2 to 7.1.3.
- [Release notes](https://github.com/pytest-dev/pytest/releases)
- [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst)
- [Commits](https://github.com/pytest-dev/pytest/compare/7.1.2...7.1.3)

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

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-05 16:26:19 +03:00
Søren Howe Gersager
678a5a0302 Add django.db.models.functions.Collate (#1143) 2022-09-05 14:03:02 +01:00
PIG208
c0414c7b02 Reflect the deprecation of get_response being None. (#1086)
* Reflect the deprecation of get_response being None.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Type get_response with a callback protocol.

Otherwise, calling `self.get_response(request)` in a subclass of
`MiddlewareMixin` runs into `Invalid self argument` error.

This is a workaround for https://github.com/python/mypy/issues/5485.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2022-09-03 23:53:14 +03:00
Daniel Brown
12e8009600 fix type hint for GenericSitemap(info_dict) (#1111) 2022-09-02 12:48:19 +03:00
github-actions[bot]
2df1b6fecd Auto-update pre-commit hooks (#1142)
Co-authored-by: sobolevn <sobolevn@users.noreply.github.com>
2022-09-01 11:52:06 +03:00
dependabot[bot]
f477317059 Bump black from 22.6.0 to 22.8.0 (#1141)
Bumps [black](https://github.com/psf/black) from 22.6.0 to 22.8.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.6.0...22.8.0)

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

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-01 11:43:22 +03:00
Sebastiaan Zeeff
a1d3aec3a2 Fix return type for django.shortcuts.render (#1140)
The return type for calling `shorcuts.render` without providing a value
for the `permanent` kwarg was `HttpResponsePermanentRedirect`, while it
should be `HttpResponseRedirect`.

The reason is that the first two overloads of the type stub overlap for
the case of using the default argument. While `mypy` does issue an error
for this, it was previously ignored with the `# type: ignore` comment.

As the first overload annotates the function as having the return type
`HttpResponsePermanentRedirect`, this would make mypy assume that the
return type is that instead of `HttpResponseRedirect`.

Since calling `django.shortcuts.redirect` without providing an argument
for `permanent` is the same as calling it with a `Literal[False]`, as
the default value is a `False`, we can improve the stub by only
specifying the option to use the default argument (`= ...`) in the
second overload. This also removes the overlap in stub definitions,
meaning that the `# type: ignore` can now be removed.

This commit fixes #1138.
2022-08-30 15:05:39 +03:00
Adam Johnson
74e31c7562 Add QuerySet.__aiter__() (#1136) 2022-08-28 15:15:28 +03:00
Adam Johnson
0635afa57c Fix Manager.contains and bulk_create (#1135) 2022-08-28 12:01:40 +03:00
Adam Johnson
3622a61442 Improve types for QuerySet.contains and bulk_create (#1134)
* Improve types for QuerySet.contains and bulk_create

* models.Model
2022-08-28 11:37:37 +03:00
Adam Johnson
bfad3b05c1 Improve database backend types (#1132)
* Improve database backend types

* fixes
2022-08-28 11:15:22 +03:00
Adam Johnson
11c587867d Add Q.__xor__ (#1133) 2022-08-28 11:14:03 +03:00
Joon Hwan 김준환
d0a9793917 Add async queryset for Django 4.1 (#1131)
* Add async queryset for Django 4.1

* dedup

* fix to async
2022-08-28 11:13:56 +03:00
PIG208
18a055124a Return Promise for lazy functions. (#689)
* Type the return value of lazy translation functions as Promise.

The return value of the lazy translation functions is a proxied
`Promise` object.
https://github.com/django/django/blob/3.2.6/django/utils/translation/__init__.py#L135-L221.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Mark unicode translation functions for deprecation.

https://docs.djangoproject.com/en/4.0/releases/4.0/#features-removed-in-4-0.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Add proxied functions for Promise.

Although there is nothing defined in `Promise` itself, the only
instances of `Promise` are created by the `lazy` function, with magic
methods defined on it.

https://github.com/django/django/blob/3.2.6/django/utils/functional.py#L84-L191.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Add _StrPromise as a special type for Promise objects for str.

This allows the user to access methods defined on lazy strings while
still letting mypy be aware of that they are not instances of `str`.

The definitions for some of the magic methods are pulled from typeshed. We need
those definitions in the stubs so that `_StrPromise` objects will work properly
with operators, as refining operator types is tricky with the mypy
plugins API.

The rest of the methods will be covered by an attribute hook.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Implement _StrPromise attribute hook.

This implements an attribute hook that provides type information for
methods that are available on `builtins.str` for `_StrPromise` except
the supported operators. This allows us to avoid copying stubs from the
builtins for all supported methods on `str`.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Allow message being a _StrPromise object for RegexValidator.

One intended usage of lazystr is to postpone the translation of the
error message of a validation error. It is possible that we pass a
Promise (specifically _StrPromise) and only evaluate it when a
ValidationError is raised.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Refactor _StrPromise attribtue hook with analyze_member_access.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2022-08-27 21:08:31 +03:00
PIG208
11ded9deaf Enhance stubs for csrf decorators. (#1130)
* Use inherited types from CsrfViewMiddleware.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

* Define decorators generated from middleware with TypeVars.

csrf_protect and etc. are created via the decorator_from_middleware
helper, which doesn't modify the original signature of the wrapped view
function. Using TypeVar helps preserve the original type of the
decorated callable.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2022-08-27 20:29:30 +03:00
Petter Friberg
8bd00ba25a Type samesite values as literals 'Lax', 'Strict' or 'None' (#1110)
* Type `samesite` values as literals 'Lax', 'Strict' or 'None'

- Adjusts supported `SESSION_COOKIE_SAMESITE` values
- Adjusts supported `CSRF_COOKIE_SAMESITE` values

* Update django-stubs/conf/global_settings.pyi

* Update response.pyi

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-08-27 02:02:47 +03:00
László Károlyi
6b39050d52 Updating deconstructible (#1116)
* Updating deconstructible

* Black

* Update deconstruct.pyi

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-08-27 01:43:32 +03:00
Adam Johnson
a01ab43cc6 Add HttpRequest current_app and LANGUAGE_CODE attrs (#1127)
* Add HttpRequest.current_app

* rearrange and add LANGUAGE_CODE
2022-08-26 17:23:50 +03:00
Adam Johnson
82695e8e1c Add db Field.flatchoices (#1128)
* Add db Field.flatchoices

* @property
2022-08-26 17:23:26 +03:00