* 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_)
* 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
* Refactor to more easily support additional config options
* Notify when Manager.from_queryset happens inside model class body
- A warning will be emitted whenever `Manager.from_queryset` happens
inside of a model class body
* Resolve generated default manager types before final iteration
A default manager on a model should always exist, eventually. Although,
we extend to look through dynamically generated managers on each
iteration instead of deferring until the final iteration.
Instead of copying methods over from a QuerySet passed to a basemanager
when invoking '<BaseManager>.from_queryset', any QuerySet methods are
declared as attributes on the manager.
This allows us to properly lookup any QuerySet method types via a
'get_attribute_hook' and will thus remove disorienting phantom errors
occuring from mypy trying to resolve types only existing in the module
where the _original_ (and real) queryset method was declared.
* Fix `MyModel.objects.filter(...).my_method()`
* Fix regression: `MyModel.objects.filter(...).my_method()` no longer worked when using from_queryset
This also fixes the self-type of the copied-over methods of the manager generated by from_queryset.
Previously it was not parameterized by the model class, but used Any.
The handling of unbound types is not tested here as I have not been able to
find a way to create a test case for it. It has been manually tested
against an internal codebase.
* Remove unneeded defer.
* QuerySet.annotate returns self-type. Attribute access falls back to Any.
- QuerySets that have an annotated model do not report errors during .filter() when called with invalid fields.
- QuerySets that have an annotated model return ordinary dict rather than TypedDict for .values()
- QuerySets that have an annotated model return Any rather than typed Tuple for .values_list()
* Fix .annotate so it reuses existing annotated types. Fixes error in typechecking Django testsuite.
* Fix self-typecheck error
* Fix flake8
* Fix case of .values/.values_list before .annotate.
* Extra ignores for Django 2.2 tests (false positives due to tests assuming QuerySet.first() won't return None)
Fix mypy self-check.
* More tests + more precise typing in case annotate called before values_list.
Cleanup tests.
* Test and fix annotate in combination with values/values_list with no params.
* Remove line that does nothing :)
* Formatting fixes
* Address code review
* Fix quoting in tests after mypy changed things
* Use Final
* Use typing_extensions.Final
* Fixes after ValuesQuerySet -> _ValuesQuerySet refactor. Still not passing tests yet.
* Fix inheritance of _ValuesQuerySet and remove unneeded type ignores.
This allows the test
"annotate_values_or_values_list_before_or_after_annotate_broadens_type"
to pass.
* Make it possible to annotate user code with "annotated models", using PEP 583 Annotated type.
* Add docs
* Make QuerySet[_T] an external alias to _QuerySet[_T, _T].
This currently has the drawback that error messages display the internal type _QuerySet, with both type arguments.
See also discussion on #661 and #608.
Fixes#635: QuerySet methods on Managers (like .all()) now return QuerySets rather than Managers.
Address code review by @sobolevn.
* Support passing TypedDicts to WithAnnotations
* Add an example of an error to README regarding WithAnnotations + TypedDict.
* Fix runtime behavior of ValuesQuerySet alias (you can't extend Any, for example).
Fix some edge case with from_queryset after QuerySet changed to be an
alias to _QuerySet. Can't make a minimal test case as this only occurred
on a large internal codebase.
* Fix issue when using from_queryset in some cases when having an argument with a type annotation on the QuerySet.
The mypy docstring on anal_type says not to call defer() after it.
* Adds support for pyproject.toml files
Since mypy 0.900 the pyproject.toml files are supported.
This PR adds a support for it. It searchs for a `tool.django-stubs` section. This is an example configuration:
```
[tool.django-stubs]
django_settings_module = "config.settings.local"
```
Fixes#638
* Added TOML tests
* Use textwrap.dedent instead of trying to manually replace spaces
* Output a more clear configuration error
* Performance related improvements in config read handling
* Check python 3.6 with travis
* Revert the .travis.yml py36 inclusion
* Added tests for input error handling
* Thanks isort, isorted it out
* Make exit() function a bit more aesthetic
* Single quote -> double quote docstrings
* Whitespace removed
* Instead of using Literal types, overload QuerySet.values_list in the plugin. Fixes#43.
- Add a couple of extra type checks that Django makes:
1) 'flat' and 'named' can't be used together.
2) 'flat' is not valid when values_list is called with more than one field.
* Determine better row types for values_list/values based on fields specified.
- In the case of values_list, we use a Row type with either a single primitive, Tuple, or NamedTuple.
- In the case of values, we use a TypedDict.
- In both cases, Any is used as a fallback for individual fields if those fields cannot be resolved.
A couple other fixes I made along the way:
- Don't create reverse relation for ForeignKeys with related_name='+'
- Don't skip creating other related managers in AddRelatedManagers if a dynamic value is encountered
for related_name parameter, or if the type cannot be determined.
* Fix for TypedDict so that they are considered anonymous.
* Clean up some comments.
* Implement making TypedDict anonymous in a way that doesn't crash sometimes.
* Fix flake8 errors.
* Remove even uglier hack about making TypedDict anonymous.
* Address review comments. Write a few better comments inside tests.
* Fix crash when running with mypyc ("interpreted classes cannot inherit from compiled") due to the way I extended TypedDictType.
- Implemented the hack in another way that works on mypyc.
- Added a couple extra tests of accessing 'id' / 'pk' via values_list.
* Fix flake8 errors.
* Support annotation expressions (use type Any) for TypedDicts row types returned by values_list.
- Bonus points: handle values_list gracefully (use type Any) where Tuples are returned
where some of the fields arguments are not string literals.
- Add a couple of extra type checks that Django makes:
1) 'flat' and 'named' can't be used together.
2) 'flat' is not valid when values_list is called with more than one field.
* Support returning the correct values for the different QuerySet methods when using .values() and .values_list().
* Fix slicing on QuerySet. Fix django queries test, and remove some ignored errors that are no longer needed.
* Remove accidental change in RawQuerySet.
* Readded some still-necessary ignores to aggregation django test.
* Add more tests of first/last/earliest/last/__getitem__, per mkurnikov's comments.
- Fix .iterator()
* Re-add Iterator as base-class of QuerySet.
* Make QuerySet a Collection.
* - Fix return type for QuerySet.select_for_update().
- Use correct return type for QuerySet.dates() / QuerySet.datetimes().
- Use correct type params in return type for QuerySet.__and__ / QuerySet.__or__
- Re-add Sized as base class for QuerySet.
- Add test of .all() for all _Row types.
- Add test of .get() for all _Row types.
- Remove some redundant QuerySet method tests.
* Automatically fill in second type parameter for QuerySet.
... if second parameter is omitted.
* Fix bug where models with a class variable using a manager defined would interfere with other managers.
- Fill in the type argument for that particular instance of the manager, rather than modifying the bases of the Manager type.
- Instantiate a new Instance from determine_proper_manager_type so The code doesn't crash under mypy-mypyc.
* Use helpers.reparametrize_instance per review comment.
* Updated ignored errors in Django test for get_objects_or_404.
- For some reason, `Manager[nothing]` is now removed from expected types.
However, I think this makes sense anyway, as Manager is a subclass of QuerySet.