* Add test for both issue cases
* Use generic type and add new django 4.1 `get_latest_lastmod` method
* Add Sitemap to monkeypatch
* Update test case to use generic + add failing case
* Test GenericSitemap too
* 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
* 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
* Implement support for `<QuerySet>.as_manager()`
* fixup! Implement support for `<QuerySet>.as_manager()`
* fixup! fixup! Implement support for `<QuerySet>.as_manager()`
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>
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.
* 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>
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.
* 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>
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.