mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-14 07:47:09 +08:00
Reparametrize managers without explicit type parameters (#1169)
* 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
This commit is contained in:
@@ -26,6 +26,7 @@ from mypy_django_plugin.transformers.functional import resolve_str_promise_attri
|
||||
from mypy_django_plugin.transformers.managers import (
|
||||
create_new_manager_class_from_as_manager_method,
|
||||
create_new_manager_class_from_from_queryset_method,
|
||||
reparametrize_any_manager_hook,
|
||||
resolve_manager_method,
|
||||
)
|
||||
from mypy_django_plugin.transformers.models import (
|
||||
@@ -240,6 +241,15 @@ class NewSemanalDjangoPlugin(Plugin):
|
||||
|
||||
return None
|
||||
|
||||
def get_customize_class_mro_hook(self, fullname: str) -> Optional[Callable[[ClassDefContext], None]]:
|
||||
sym = self.lookup_fully_qualified(fullname)
|
||||
if (
|
||||
sym is not None
|
||||
and isinstance(sym.node, TypeInfo)
|
||||
and sym.node.has_base(fullnames.BASE_MANAGER_CLASS_FULLNAME)
|
||||
):
|
||||
return reparametrize_any_manager_hook
|
||||
|
||||
def get_base_class_hook(self, fullname: str) -> Optional[Callable[[ClassDefContext], None]]:
|
||||
# Base class is a Model class definition
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user