Commit Graph

977 Commits

Author SHA1 Message Date
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
Adam Johnson
0120fc531a Rewrite SessionBase properties to use @property (#1129) 2022-08-26 17:22:03 +03:00
Adam Johnson
de3e13ad92 Add database Field.non_db_attrs (#1125)
* Add database Field.non_db_attrs

* Update django-stubs/db/models/fields/__init__.pyi

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-08-26 14:56:56 +03:00
Nikita Sobolev
06359013c9 Run stubs self-check on all python versions (#1126) 2022-08-26 14:36:23 +03:00
Adam Johnson
63bee32d0d Add different signatures for form assertions from Django 4.1 (#1105) 2022-08-26 13:31:45 +03:00
Adam Johnson
1a310ef7f9 Add test client response.redirect_chain (#1124) 2022-08-26 13:31:17 +03:00
Adam Johnson
8b5509b2ab Improve type hints for test client response.context (#1100)
* Improve type hints for test client response.context

* fix test
2022-08-26 13:30:18 +03:00
Nikita Sobolev
0bb1182c42 Fix CI (#1108)
* Fix CI

* Fix CI

* Fix CI

* Fix CI

* APply black

* APply black

* Fix mypy

* Fix mypy errors in django-stubs

* Fix format

* Fix plugin

* Do not patch builtins by default

* Fix mypy

* Only run mypy on 3.10 for now

* Only run mypy on 3.10 for now

* WHAT THE HELL

* Enable strict mode in mypy

* Enable strict mode in mypy

* Fix tests

* Fix tests

* Debug

* Debug

* Fix tests

* Fix tests

* Add TYPE_CHECKING debug

* Caching maybe?

* Caching maybe?

* Try explicit `${{ matrix.python-version }}`

* Remove debug

* Fix typing

* Finally
2022-08-26 13:22:55 +03:00
Adam Johnson
d2bfd3710b Improve return type for BaseCommand.execute() (#1104) 2022-08-26 13:10:24 +03:00
Adam Johnson
cf16720f28 Improve types for DiscoverRunner (#1106)
* Improve types for DiscoverRunner

* add types for class-level attrs

* Add extra methods

* Add PDBDebugResult class

* black

* Update django-stubs/test/runner.pyi

* fix load_with_patterns return

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-08-26 13:09:41 +03:00
Adam Johnson
063a35f4d0 Expose HttpResponseBase in django.http (#1121)
* Expose HttpResponseBase in django.http

* isort
2022-08-26 12:45:22 +03:00
Adam Johnson
9ba4a55c93 Improve types for CheckMessage subclasses (#1107) 2022-08-26 12:44:18 +03:00
Adam Johnson
561140a584 Allow None to be passed to Paginator.get_page (#1101) 2022-08-26 12:40:53 +03:00
Adam Johnson
5b705d25da Add SimpleTestCase.assertURLEqual() (#1102) 2022-08-26 12:40:34 +03:00
Adam Johnson
f626448105 Add BaseDatabaseWrapper.operations (#1119) 2022-08-26 12:40:17 +03:00
Adam Johnson
63ea17744f Add HttpResponseBase.__contains__ (#1099) 2022-08-26 12:37:23 +03:00
Adam Johnson
f8fca3f94f Improve hints for BaseCache (#1117)
* Improve hints for BaseCache

* fix syntax error
2022-08-26 12:36:58 +03:00
Anders Kaseorg
041b66a6aa Prevent building an editable wheel with setuptools<64 (#1123)
This seems to be needed for passing CI now.

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

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2022-08-26 11:55:41 +03:00
Alex Nathanail
3ac34f1108 Fix base_field type for SimpleArrayField (#1097)
* Fix base_field type for SimpleArrayField

* Add test which fails without this change
2022-08-10 16:16:54 +03:00
PIG208
a1445291fd Improve type annotation for RunSQL (#1090)
* Allow passing heterogeneous list or tuple to RunSQL.

The sqls to be executed do not necessarily need to be a homogeneous list
or tuple containing only lists or tuples or strs. It can be a mix of
everything.

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

* Support passing dict as a sql param.

The 2-item tuple for `sql` can have a `dict` as the second item
for parameters. This behavior is the same as using
`cursor.execute` for backends except SQLite.

Relevant implementation:
5f76002500/django/db/migrations/operations/special.py (L119-L133)

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

* Add a test case for RunSQL.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2022-08-09 10:36:36 +03:00
PIG208
7b18e354f1 Add preset options list to makemessages command. (#1091)
These options can be found here:

0756c61f2a/django/core/management/commands/makemessages.py (L222-L225)

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2022-08-09 00:31:34 +03:00
PIG208
db1edeeabf Fix a broken test case after the Django 4.1 update. (#1093)
This fixes the CI starting occur on #1086 and following PRs due to the release
of Django 4.1 (https://docs.djangoproject.com/en/4.1/releases/4.1/) which
shipped the change

    # Even if this relation is not to pk, we require still pk value.
    # The wish is that the instance has been already saved to DB,
    # although having a pk value isn't a guarantee of that.
    if self.instance.pk is None:
        raise ValueError(
            f"{instance.__class__.__name__!r} instance needs to have a primary "
            f"key value before this relationship can be used."
        )

in https://github.com/django/django/pull/15318.
2022-08-09 00:18:08 +03:00
Anders Kaseorg
589f315926 Remove trailing whitespace in README to fix CI failure (#1084)
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2022-08-02 11:07:21 +03:00
Tony Narlock
5334a80c9b docs(README): Fix indentation in list and examples (#1083)
Run examples through black for uniformity, link `HttpModel`
2022-08-02 02:39:14 +03:00
Thibaut Decombe
966472994b Allow float for min_value and max_value of FloatField (#1081)
Co-authored-by: Thibaut <thibaut.d@hellowatt.fr>
2022-08-01 14:17:50 +03:00
Anders Kaseorg
41804f0e8d Fix OutputWrapper.style_func type (#1080)
style_func has a setter that converts None to lambda x: x, so the
getter cannot return None.

https://github.com/django/django/blob/4.0.6/django/core/management/base.py#L141-L150

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2022-07-30 12:58:41 +03:00
PIG208
0e9ebf838b Support Lookup generics. (#1079)
Custom `Lookup` implementation will run into
'Missing type parameters for generic type "Lookup"' without having
`Lookup` monkey-patched with django-stubs-ext.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2022-07-28 21:08:56 +03:00
github-actions[bot]
196e6743ec Auto-update pre-commit hooks (#1076)
Co-authored-by: sobolevn <sobolevn@users.noreply.github.com>
2022-07-27 10:06:55 +03:00
Adam Johnson
efc2d04ead Improve types for @require_http_methods (#1075) 2022-07-26 20:47:05 +03:00
PIG208
56f9300d0d Improve stubs for contrib.postgres.operations. (#1071)
* Improve stubs for contrib.postgres.operations.

This adds a bunch of missing operations in contrib.postgres.operations.

Documentation: https://docs.djangoproject.com/en/4.0/ref/contrib/postgres/operations/#managing-collations-using-migrations
Source code: 2fac0a1808/django/contrib/postgres/operations.py

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

* Add migration_name_fragment to Operation.

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

* Remove redefinition of methods in subclasses.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2022-07-24 10:40:13 +03:00
Anders Kaseorg
20f0702f86 Tighten management.get_commands type (#1074)
get_commands has not actually returned BaseCommand items since Django
1.4.  See https://github.com/django/django/pull/15876.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2022-07-24 10:38:32 +03:00
PIG208
f3f80164a8 Fix type annotation of message_dict. (#1073)
When message_dict is accessed, it either raises an `AttributeError` or
returns a `dict`. There is no way for it to be `Optional`.

caad462fea/django/core/exceptions.py (L170-L176)

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
2022-07-23 16:55:58 +03:00
Anders Kaseorg
3d8d900487 Fix overloads and remove PathLike in finders (#1063)
* Fix overloads in finders

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

* Remove PathLike from finders

Django really requires these paths to be str.  For example, in
FileSystemFinder, .find(path) calls .find_location(…, path, …) which
evaluates path.startswith(prefix) and path[len(prefix) :]; these don’t
work on arbitrary PathLike objects.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2022-07-22 10:35:24 +03:00
PIG208
563e947402 Improve type annotation of DiscoverRunner. (#1069)
The return type of DiscoverRunner.get_resultclass should
be Optional[Type[TextTestResult]] given that it may also return PDBDebugResult:
0dd2920909/django/test/runner.py (L958-L962)

`DicoverRunner.run_tests` accepts `None` for `extra_tests` because
that's already the default value for it:
0dd2920909/django/test/runner.py (L1030)
2022-07-22 10:34:26 +03:00
github-actions[bot]
62c09c064c Auto-update pre-commit hooks (#1070)
* Auto-update pre-commit hooks

* Update pre-commit-autoupdate.yml

Co-authored-by: sobolevn <sobolevn@users.noreply.github.com>
Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-07-22 10:07:15 +03:00
Nikita Sobolev
89d0a10939 Create pre-commit-autoupdate.yml 2022-07-22 09:34:53 +03:00
Jordan Hayashi
0246f9fcf3 Use a more general type for django.core.mail.send_mass_mail's datatuple (#1062)
* Use a datatuple in django.core.mail.send_mass_mail

Even though the implementation works for both a List of tuples and a
tuple of tuples, the docs recommend using a tuple.

https://github.com/django/django/blob/main/django/core/mail/__init__.py#L112
https://docs.djangoproject.com/en/4.0/topics/email/#send-mass-mail

* Use a more general type for send_mass_mail's datatuple
2022-07-19 21:12:30 +03:00