Commit Graph

883 Commits

Author SHA1 Message Date
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
Marti Raudsepp
1a36c6c379 Improve type hints of URL conf & include() (#949)
* Improve type hints of URL conf & include()

The type of `urlpatterns` list is `List[Union[URLPattern, URLResolver]]`.

* https://docs.djangoproject.com/en/dev/ref/urls/#django.urls.include
* https://docs.djangoproject.com/en/4.0/ref/urls/

* Alias _AnyURL = Union[URLPattern, URLResolver]

* Fix extract_views_from_urlpatterns
2022-05-06 09:00:21 +03:00
dependabot[bot]
4a5d330228 Bump pre-commit from 2.18.1 to 2.19.0 (#950)
Bumps [pre-commit](https://github.com/pre-commit/pre-commit) from 2.18.1 to 2.19.0.
- [Release notes](https://github.com/pre-commit/pre-commit/releases)
- [Changelog](https://github.com/pre-commit/pre-commit/blob/main/CHANGELOG.md)
- [Commits](https://github.com/pre-commit/pre-commit/compare/v2.18.1...v2.19.0)

---
updated-dependencies:
- dependency-name: pre-commit
  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-05-06 08:57:20 +03:00
sobolevn
69d5aa94b0 Move release.sh to scripts/ 2022-05-02 13:01:38 +03:00
Damian Zaremba
2ef7ff3309 Bump mypy 0.950 (#939)
* Bump mypy to 0.95x

* Remove the * for inferred types

There was an upstream change (https://github.com/python/mypy/pull/12459)
to remove * from inferred types in the reveal_type output.

As we are asserting the * to exist, all the test cases are now failing
on the 0.950 release. Removing the expected * to mirror the upstream
behaviour change should resolve the test failures.
2022-04-29 14:44:33 +03:00
Marti Raudsepp
0caee74490 Fix typecheck default Django version (#944)
Currently running `typecheck_tests.py` without arguments fails with "KeyError: '3.0'"
2022-04-29 10:21:20 +03:00
Marti Raudsepp
e0f45e4778 Update SimpleTestCase.assert method response types (#942)
Since PR 909, SimpleTestCase.client.get() etc methods return a class that no longer derives from `HttpResponse`, but instead `HttpResponseBase`, the `assert*` methods taking response should be updated as well.

Discovered while trying to update djangorestframework-stubs to django-stubs as of master.
2022-04-29 09:03:01 +03:00
Marti Raudsepp
f7b6a7beb4 Fix URLPattern, URLResolver pattern type (#941) 2022-04-29 09:02:19 +03:00
Marti Raudsepp
2b0bfdb46e Restore Python 3.7 compatibility (#945)
django-stubs still supports Python 3.7, but the `/` positional-only parameter syntax is supported only in Python 3.8+.

Not sure why this error wasn't caught in CI.
2022-04-29 08:51:56 +03:00
Marti Raudsepp
c836c3ac3a Fix ValidationError false positive on nested inputs (#943)
Reverts parts of PR 909.
2022-04-28 19:19:18 +03:00
sterliakov
6226381484 Recover after #909 (#925)
* Fix stubs related to `(Async)RequestFactory` and `(Async)Client`

* Revert incorrect removal.

* Allow set as `unique_together`, use shared type alias.

* Revert `Q.__init__` to use only `*args, **kwargs` to remove false-positive with `Q(**{...})`

* Add abstract methods to `HttpResponseBase` to create common interface.

* Remove monkey-patched attributes from `HttpResponseBase` subclasses.

* Add QueryDict mutability checks (+ plugin support)

* Fix lint

* Return back GenericForeignKey to `Options.get_fields`

* Minor fixup

* Make plugin code typecheck with `--warn-unreachable`, minor performance increase.

* Better types for `{unique, index}_together` and Options.

* Fix odd type of `URLResolver.urlconf_name` which isn't a str actually.

* Better types for field migration operations.

* Revert form.files to `MultiValueDict[str, UploadedFile]`

* Compatibility fix (#916)

* Do not assume that `Annotated` is always related to django-stubs (fixes #893)

* Restrict `FormView.get_form` return type to `_FormT` (class type argument). Now it is resolved to `form_class` argument if present, but also errors if it is not subclass of _FormT

* Fix CI (make test runnable on 3.8)

* Fix CI (make test runnable on 3.8 _again_)
2022-04-28 13:01:37 +03:00
Guillaume Andreu Sabater
16499a22ab added unique annotation on model Field (#936) 2022-04-27 22:57:58 +03:00
dependabot[bot]
268ec3bcd5 Bump pytest from 7.1.1 to 7.1.2 (#932)
Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.1.1 to 7.1.2.
- [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.1...7.1.2)

---
updated-dependencies:
- dependency-name: pytest
  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-04-25 19:58:02 +03:00
Oleg Höfling
8e875b13f7 add fail_silently attribute for BaseEmailBackend instances (#931)
Signed-off-by: Oleg Hoefling <oleg.hoefling@ionos.com>
2022-04-21 19:45:51 +03:00
Chris Beaven
a1b647700b Fix incorrect instance arg for BaseInlineFormSet.__init__ (#928)
* Fix BaseInlineFormSet generic to retain parent model class info

* Add in test for generic formset improvements
2022-04-19 08:59:50 +03:00
rolandcrosby-check
30bf4dab6c Update media render return values to SafeString (#923) 2022-04-14 23:53:52 +03:00
Xavier Francisco
40bf7a562d Add missing type for setup_databases (#919)
* Add missing type for setup_databases

`django.test.utils` was seemingly missing the type for `setup_databases`. 

This change resolves my issue locally. The type was copied directly from `django.test.runner`.

* Fix typecheck_tests runner

Co-authored-by: Xavier Francisco <xavier.n.francisco@gmail.com>
2022-04-13 12:56:57 +03:00
Jim King
e468ee97da issue-914: ValidationError.error_dict type fix (#915) 2022-04-09 10:06:45 +03:00
Guillaume Andreu Sabater
d8b417456f added ExtractIsoWeekDay (#912)
https://docs.djangoproject.com/en/3.2/ref/models/database-functions/#django.db.models.functions.ExtractIsoWeekDay
2022-04-06 20:08:23 +03:00
Nikita Sobolev
2dad9228eb Switch to setuptools (#911) 2022-04-06 13:02:56 +03:00
dependabot[bot]
21bed1ccf3 Bump pre-commit from 2.17.0 to 2.18.1 (#910)
Bumps [pre-commit](https://github.com/pre-commit/pre-commit) from 2.17.0 to 2.18.1.
- [Release notes](https://github.com/pre-commit/pre-commit/releases)
- [Changelog](https://github.com/pre-commit/pre-commit/blob/main/CHANGELOG.md)
- [Commits](https://github.com/pre-commit/pre-commit/compare/v2.17.0...v2.18.1)

---
updated-dependencies:
- dependency-name: pre-commit
  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-04-04 14:18:28 +03:00
sterliakov
f69e0639c7 Large update (#909)
* Make module declaration precise.

* Make settings match real file.

* Replace `include` with import.

* Make types more specific.

* Replace `WSGIRequest` with `HttpRequest` where possible.

* Replace all `OrderedDict` occurrences with plain `Dict` (it is not used in Django 3.2 and later)

* Add fake datastructures for convenience: _PropertyDescriptor and _ListOrTuple now can live here. Added _IndexableCollection (often useful as alias for 'sequence or queryset')

* Actualize other datastructures.

* Rework MultiValueDict to reflect the fact that some methods can return empty list instead of value.

* Deprecate SafeText in favor of SafeString.

* Minor improvements to utils

* Disallow using str in TimeFormat and DateFormat, drop removed fmt `B`

* Do not let classproperty expect classmethod, make return value covariant.

* Sync with real file.

* Improve types for timezone.

* Sync deprecated, new and removed features in translation utils.

* Drop removed files, sync huge deprecations.

* Fix incompatible decorators (properties, contextmanagers)

* Rework pagination.

* Sync validators with real code. Add _ValidatorCallable for any external use (field validation etc.)

* Add shared type definitions (for fields of both forms and models). Actualize model fields. Mark keyword-only args explicitly in stubs (where code uses **kwargs). Disallow bytes for verbose_name.

* Make all checks return Sequence[CheckMessage] or subclass to be covariant.

* Add bidirectional references between backend.base and other files. Replace some Any's with specific types.

* Actualize db.migrations: remove removed methods, replace "None" annotations in wrong places, improve some wrong annotations.

* Actualize db.utils to match real file.

* Replace FileResponse and TemplateResponse with HttpResponse(Base) where needed: at least HttpResponseNotModified/HttpResponseRedirect can be returned instead of it, so annotation was wrong.

* Replace Any in forms where possible. Actualize class bases and method arguments.

* Improve typing of serializers.

* Actualize views, rename variable bound to Model to _M for consistency.

* Make types of file-related code consistent. Disallow using bytes as path, because many methods expect str-only paths. Make File inherit from IO[AnyStr] instead of IO[Any]: it makes impossible to instantiate file of union type, but allows precise types for some methods.

* Minor improvements: stop using None as annotation in wrong places, replace obvious Any's with precise types, actualize methods (missing/renamed/signature changed).

* Allow less specific containers, replace Any's with specific types.

* Improve types for requests and responses.

* Use AbstractBaseUser instead of User in auth.

* Use broader type for permission_required

* Use wider container types. Add 'type: ignore' to avoid issues with mypy.stubtest.

* Disallow using backend class as argument (it is passed to import_string).

* Add required methods to PasseordValidator.

* Allow using Path instance as argument.

* Actualize methods.

* Add 'type: ignore' to avoid issues with mypy.stubtest.

* Replace Any's with specific types and BaseForm with ModelForm.

* Actualize contrib.postgres

* Remove render_to_response, add 'get_absolute_url' to corresponding protocol.

* Actualize signers.

* Use precise types for handlers. Disallow str as stream type for LimitedStream.

* Exact types for ValidationError

* Replace wrong used Union with Sequence.

* Actualize static handlers.

* More specific types for admin. Fixes #874.

* Improve types and replace 'Tags' with str (it isn't Enum, so annotation was wrong).

* Replace Any with specific types, actualize signatures.

* Add async variants of handlers and clients. Use fake class to distinguish between request types in RequestFactory and AsyncRequestFactory.

* Fix signature, minor improvements.

* Actualize signatures and class names, replace Any with more specific types.

* Fix signature.

* Add some missing methods to Collector

* Combinable rarely returns Self type: almost always it's CombinedExpression.

* No Random in source anymore.

* Drop removed SimpleCol.

* Replace _OutputField with Field: nothing in docs about strings.

* Introduce reusable types, add missing methods. Remove strange types (probably created by stubgen). Remove RawQuery from Compiler: it obviously doesn't work with RawQuery.

* Use literal constants.

* Actualize base classes.

* Callable is not accepted by get_field.

* Add precise types.

* Use property and broader containers where possible. Add missing methods.

* Actualize indexes.

* More specific types for signals.

* Fix signatures, drop missing methods.

* Actualize window functions to match source.

* Actualize text functions, add missing methods, use type aliases for consistency.

* Add missing property decorators, methods and attributes. Use type aliases. Remove absent YearComparisonLookup and any SafeText references (they aren't related to lookups at all).

* Use bound TypeVar, mark all BuiltinLookup descendants as generic explicitly. Remove strange Union from Lookup.__init__

* Apply type alias, fix base class and argument name.

* Actualize BaseExpression methods.

* Fix imports.

* Add missing class and fix incompatible bases.

* Use same types in __init__ and attribute.

* OrderBy accepts F or Expression.

* Non-expressions are converted to Values.

* Add missing attributes.

* Add missing methods, fix 'None' argument type.

* Define properties where possible, remove 'None' argument annotations, remove inadequate type in make_immutable_fields_list.

* Remove absent QueryWrapper. Replace some Any with precise types.

* Fix wrong types and actualize signatures. Deny ManagerDescriptor.__get__ on model instances.

* Use more specific types.

* Arity can be None in subclasses.

* Reformat with black

* Make DeletionMixin generic.

* Fix wrong type variable in _RequestFactory.

* Fix variable name in signature.

* Disallow returning None from Form.clean()

* Allow again returning None from Form.clean

* Drop some unused imports.

* Add tests for MultiValueDict.

* Add tests for utils.timezone.

* Fix #834.

* Add more files to import_all test

* Allow None for `context_object_name`

* Fix CI

* Fix test to work on python 3.8
2022-04-04 00:41:41 +03:00
Sigurd Ljødal
dc4c0d9ee4 Emit error instead of raising on union custom QuerySet (#907)
* Add reproducer for failing case

* Emit warning instead of crashing when encountering enum

* Remove prints, slightly tweak error message

* Remove unused import

* Run black and isort

* Run isort on .pyi file

* Remove unrelated issue from test case
2022-04-01 22:07:55 +03:00
Petter Friberg
0e98cc9114 Don't rely on django.db.models.manager.Manager metadata for dynamically created manager (#904) 2022-03-31 23:37:37 +03:00
Sigurd Ljødal
76e3fdb479 Fix missing related managers on some models (#902)
* Fix missing related managers on some models

I was seeing an issue where some related managers were missing from some
models. Traced the issue down to this line, where it appears that if we
hit a relation with a non-default(?) reverse manager the iteration
stopped. I _think_ this is supposed to be a continue statement instead.
It appears to work in the project I'm working in at least.

* Add test case

* Add test case
2022-03-31 23:36:22 +03:00
Marti Raudsepp
49d855547b Improve MultiValueDict/QueryDict dict() return (#899)
According to Django documentation and code, the `MultiValueDict.dict()` method only returns singular values for each key, never a list.

https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.QueryDict.dict

3de787a70b/django/utils/datastructures.py (L215-L217)
2022-03-31 11:47:45 +03:00
Marti Raudsepp
212ef40c3d Update Black dependency to fix CI lint (#900)
* Update Black dependency to fix CI lint

Closes #896.

Black 22.3.0 fixes incompatibility with Click 8.1.0:
https://github.com/psf/black/pull/2966

This currently causes the CI to fail, e.g. https://github.com/typeddjango/django-stubs/runs/5756075543

* Reformat with Black v22
2022-03-31 11:29:31 +03:00
Petter Friberg
92e5f202ac Cache dynamically created manager nodes (#840)
- Non plugin generated, "cross_ref"s points to dynamically
  created managers (e.g. `Model.objects`) and can make Mypy fail on
  cached runs
2022-03-31 10:21:21 +03:00
sobolevn
4e3f9d6f06 Version 0.10.1 release 2022-03-28 16:09:09 +03:00
Mark Gregson
2fad97af03 login_form is a class (#885) (#891) 2022-03-28 08:44:40 +03:00
henribru
a14fb28f33 Import Literal from typing_extensions for 3.7 compatibility (#889) 2022-03-27 20:28:52 +03:00
henribru
aa5f114575 Remove Python 3.6 trove classifier (#887) 2022-03-26 14:40:24 +03:00
Nikita Sobolev
3c58270a78 Version 1.10.0 release (#886)
* Version 1.10.0 release

* Fixes CI

* Fixes CI
2022-03-26 09:22:13 +03:00
Konstantin Alekseev
3f340c9df3 Fix mypy cache of WithAnnotation types (#725) 2022-03-25 01:13:20 +03:00
w0rp
1672b54c89 Set type parameters for Field in get_fields() (#882)
* Set type parameters for Field in get_fields()

This fixes an issue with Pyright strict type checking where Pyright complains that the type parameters aren't known.

* Fix type parameters in other methods
2022-03-25 00:14:16 +03:00
Sebastian Wagner
32a33c332d Don't serialize annotated types (#881)
Signed-off-by: Sebastian Wagner <sebastian@inter.link>

Co-authored-by: Sebastian Wagner <sebastian@inter.link>
2022-03-22 14:33:52 +03:00
Anderson Luiz de Souza
10e06947d7 Fix missing args on SlugField.__init__ (#879) 2022-03-20 19:40:55 +03:00
dependabot[bot]
f4d3895595 Bump pytest from 7.1.0 to 7.1.1 (#880)
Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.1.0 to 7.1.1.
- [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.0...7.1.1)

---
updated-dependencies:
- dependency-name: pytest
  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-03-19 20:37:03 +03:00
Himanshu Balasamanta
5c75869dd3 Fixes #822 (#868)
Signed-off-by: Himanshu-Balasamanta <himanshubb.eee18@itbhu.ac.in>
2022-03-15 12:46:49 +03:00