Commit Graph

1013 Commits

Author SHA1 Message Date
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
dependabot[bot]
acfafaae14 Bump pytest from 7.0.1 to 7.1.0 (#869)
Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.0.1 to 7.1.0.
- [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.0.1...7.1.0)

---
updated-dependencies:
- dependency-name: pytest
  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-03-14 21:27:12 +03:00
Himanshu Balasamanta
f9f6c827c1 Fixes #870 (#871)
* Fixes #870

Signed-off-by: Himanshu-Balasamanta <himanshubb.eee18@itbhu.ac.in>

* Updated mypy version in setup.py to == 0.931

* Update setup.py

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
2022-03-14 21:17:53 +03:00
Adam Johnson
eb6991b008 Improve forms stubs (#862)
* `default_renderer` may be a renderer class, instance, or `None`: https://docs.djangoproject.com/en/4.0/ref/forms/api/#django.forms.Form.default_renderer
* `field_order` should be a list/sequence of field names, or `None`: https://docs.djangoproject.com/en/4.0/ref/forms/api/#django.forms.Form.field_order
* `cleaned_data` should be a dict/mapping of field names to values, as returned by `clean()`: https://docs.djangoproject.com/en/4.0/ref/forms/api/#django.forms.Form.cleaned_data . I similarly updated `clean()` to allow arbitrary mappings, since it may be legitimate to use some special mapping class.
* `clean()` does not need to return a mapping - https://docs.djangoproject.com/en/4.0/ref/forms/validation/#validating-fields-with-clean : “If your form inherits another that doesn’t return a `cleaned_data` dictionary in its `clean()` method (doing so is optional)...”
* `is_multipart` returns a `bool`: https://docs.djangoproject.com/en/4.0/ref/forms/api/#django.forms.Form.is_multipart
* `hidden_fields` and `visible_fields` aren't documented, but they return lists of `BoundField` instances: d8b437b1fb/django/forms/forms.py (L501-L513)
2022-03-02 18:02:54 +03:00
dependabot[bot]
078925a0fc Bump actions/checkout from 2 to 3 (#861)
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  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-03-02 11:05:16 +03:00
dependabot[bot]
cf31c1de7b Bump actions/setup-python from 2 to 3 (#860)
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 2 to 3.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](https://github.com/actions/setup-python/compare/v2...v3)

---
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-03-01 09:42:54 +03:00
Ethan Corey
104012b817 Added widget_type annotation to BoundField (#855)
* Add widget_type annotation to BoundField

See https://github.com/django/django/blob/main/django/forms/boundfield.py#L283

* Tweaked annotation to be `AnyStr`, not `str`

* Reverted to use `str` as return type
2022-02-22 22:47:43 +03:00
rolandcrosby-check
850df1655a Make formfield_from_dbfield return forms.Field instead of models.Field (#857) 2022-02-22 20:44:44 +03:00
dependabot[bot]
30bed85e0d Bump gitpython from 3.1.20 to 3.1.27 (#854)
Bumps [gitpython](https://github.com/gitpython-developers/GitPython) from 3.1.20 to 3.1.27.
- [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.20...3.1.27)

---
updated-dependencies:
- dependency-name: gitpython
  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-02-21 09:47:17 +03:00
Joon Hwan 김준환
ab50fb9876 cache_page should be Optional[float] . (#851)
* cache_page can use None .

* Apply black
2022-02-14 15:14:28 +03:00
Joon Hwan 김준환
319ab7f9f7 get_cache_key can have multiple httprequest types. (#852)
* Update cache.pyi

* Apply black
2022-02-14 15:06:01 +03:00
dependabot[bot]
017ac1ce85 Bump pytest from 7.0.0 to 7.0.1 (#850)
Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.0.0 to 7.0.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.0.0...7.0.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-02-14 10:50:43 +03:00
Jacob Walls
bf84546b9e Fix return type of MigrationRecorder.applied_migrations() (#793)
Matches return type of MigrationLoader.applied_migrations, which reads from here.
2022-02-10 18:29:14 +03:00
Kevin Marsh
3eab36a5c4 DatabaseClient: add missing class methods and reflect Django 3.2 refactor (#846)
* DatabaseClient: add missing class method `settings_to_cmd_args_env` and add missing arg to `runshell`

The `DatabaseClient.runshell()` was refactored in Django 3.2 to be more standardized
across the different database backends.

* DatabaseClient: make `settings_dict` dict type better by specifying key/value types

* tests: add missing db backend client files to `import_all_modules`
2022-02-10 09:29:44 +03:00
dependabot[bot]
01a31d2fd5 Bump pytest from 6.2.5 to 7.0.0 (#845)
Bumps [pytest](https://github.com/pytest-dev/pytest) from 6.2.5 to 7.0.0.
- [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/6.2.5...7.0.0)

---
updated-dependencies:
- dependency-name: pytest
  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-02-07 09:12:33 +03:00
Rob Percival
74083c9f8a Correct return type of get_commands() (#838)
According to the docstring for this function, "the instantiated module can be placed in the dictionary in place of the application name".
2022-01-31 20:28:32 +03:00
dependabot[bot]
8843acde3e Bump black from 21.12b0 to 22.1.0 (#836)
Bumps [black](https://github.com/psf/black) from 21.12b0 to 22.1.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/commits/22.1.0)

---
updated-dependencies:
- dependency-name: black
  dependency-type: direct:production
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-01-31 08:45:07 +03:00
Petter Friberg
8aae836a26 Model.__init__ supporting same typing as assigment (#835)
* `Model.__init__` supporting same typing as assigment

* Update mypy_django_plugin/django/context.py
2022-01-29 12:07:26 +03:00
Seth Yastrov
c556668d7a Attempt to fix 'INTERNAL ERROR using annotate'. (#753)
KeyError: "Failed qualified lookup: '_AnyAttrAllowed' (fullname =
'django._AnyAttrAllowed')."

https://github.com/typeddjango/django-stubs/issues/745
2022-01-28 21:43:03 +03:00
Cory Dolphin
28d6dc992c Export Datasource, Driver from gdal (#797) 2022-01-28 21:42:26 +03:00
emma-blossom
73290597f8 Make SomeModel._default_manager return a BaseManager[SomeModel] instead of BaseManager[Model] (#817)
* _default_manager has more specific type for TypeVars

* remove unnecessary # type: ignore

* add test for _base_manager

* add overloads for classproperty.__get__

* readd # type: ignore for WSGIRequestHandler.connection, fails in github's pipeline

* fix _base_manager test: mypy reveals an inferred type

Co-authored-by: Michael Pöhle <michael.poehle@polyteia.de>
2022-01-28 21:42:11 +03:00