mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-14 15:57:08 +08:00
* 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_)
This commit is contained in:
@@ -35,6 +35,7 @@ except ImportError:
|
||||
if TYPE_CHECKING:
|
||||
from django.apps.registry import Apps # noqa: F401
|
||||
from django.conf import LazySettings # noqa: F401
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||
|
||||
|
||||
@contextmanager
|
||||
@@ -100,9 +101,6 @@ class DjangoContext:
|
||||
@cached_property
|
||||
def model_modules(self) -> Dict[str, Set[Type[Model]]]:
|
||||
"""All modules that contain Django models."""
|
||||
if self.apps_registry is None:
|
||||
return {}
|
||||
|
||||
modules: Dict[str, Set[Type[Model]]] = defaultdict(set)
|
||||
for concrete_model_cls in self.apps_registry.get_models():
|
||||
modules[concrete_model_cls.__module__].add(concrete_model_cls)
|
||||
@@ -327,7 +325,7 @@ class DjangoContext:
|
||||
related_model_cls = field.field.model
|
||||
|
||||
if isinstance(related_model_cls, str):
|
||||
if related_model_cls == "self":
|
||||
if related_model_cls == "self": # type: ignore[unreachable]
|
||||
# same model
|
||||
related_model_cls = field.model
|
||||
elif "." not in related_model_cls:
|
||||
@@ -343,7 +341,7 @@ class DjangoContext:
|
||||
self, field_parts: Iterable[str], model_cls: Type[Model]
|
||||
) -> Union[Field, ForeignObjectRel]:
|
||||
currently_observed_model = model_cls
|
||||
field: Union[Field, ForeignObjectRel, None] = None
|
||||
field: Union[Field, ForeignObjectRel, GenericForeignKey, None] = None
|
||||
for field_part in field_parts:
|
||||
if field_part == "pk":
|
||||
field = self.get_primary_key_field(currently_observed_model)
|
||||
@@ -359,15 +357,16 @@ class DjangoContext:
|
||||
if isinstance(field, ForeignObjectRel):
|
||||
currently_observed_model = field.related_model
|
||||
|
||||
assert field is not None
|
||||
# Guaranteed by `query.solve_lookup_type` before.
|
||||
assert isinstance(field, (Field, ForeignObjectRel))
|
||||
return field
|
||||
|
||||
def resolve_lookup_into_field(self, model_cls: Type[Model], lookup: str) -> Union[Field, ForeignObjectRel]:
|
||||
query = Query(model_cls)
|
||||
lookup_parts, field_parts, is_expression = query.solve_lookup_type(lookup)
|
||||
|
||||
if lookup_parts:
|
||||
raise LookupsAreUnsupported()
|
||||
|
||||
return self._resolve_field_from_parts(field_parts, model_cls)
|
||||
|
||||
def resolve_lookup_expected_type(self, ctx: MethodContext, model_cls: Type[Model], lookup: str) -> MypyType:
|
||||
|
||||
Reference in New Issue
Block a user