Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unreachable statements
Browse files Browse the repository at this point in the history
UnknownPlatypus committed Jun 16, 2023
1 parent 1ce442c commit dd5cf7b
Showing 3 changed files with 6 additions and 28 deletions.
30 changes: 6 additions & 24 deletions mypy_django_plugin/django/context.py
Original file line number Diff line number Diff line change
@@ -141,8 +141,6 @@ def get_field_lookup_exact_type(
) -> MypyType:
if isinstance(field, (RelatedField, ForeignObjectRel)):
related_model_cls = self.get_field_related_model_cls(field)
if related_model_cls is None:
return AnyType(TypeOfAny.from_error)
primary_key_field = self.get_primary_key_field(related_model_cls)
primary_key_type = self.get_field_get_type(api, primary_key_field, method="init")

@@ -225,9 +223,6 @@ def get_field_set_type_from_model_type_info(info: Optional[TypeInfo], field_name
continue

related_model = self.get_field_related_model_cls(field)
if related_model is None:
expected_types[field_name] = AnyType(TypeOfAny.from_error)
continue

if related_model._meta.proxy_for_model is not None:
related_model = related_model._meta.proxy_for_model
@@ -327,8 +322,6 @@ def get_field_get_type(
is_nullable = self.get_field_nullability(field, method)
if isinstance(field, RelatedField):
related_model_cls = self.get_field_related_model_cls(field)
if related_model_cls is None:
return AnyType(TypeOfAny.from_error)

if method in ("values", "values_list"):
primary_key_field = self.get_primary_key_field(related_model_cls)
@@ -354,7 +347,7 @@ def get_field_related_model_cls(self, field: Union["RelatedField[Any, Any]", For
related_model_cls = field.model
elif "." not in related_model_cls:
# same file model
related_model_fullname = field.model.__module__ + "." + related_model_cls
related_model_fullname = f"{field.model.__module__}.{related_model_cls}"
related_model_cls = self.get_model_class_by_fullname(related_model_fullname)
if related_model_cls is None:
raise UnregisteredModelError
@@ -368,7 +361,7 @@ def get_field_related_model_cls(self, field: Union["RelatedField[Any, Any]", For

def _resolve_field_from_parts(
self, field_parts: Iterable[str], model_cls: Type[Model]
) -> Union["Field[Any, Any]", ForeignObjectRel, None]:
) -> Union["Field[Any, Any]", ForeignObjectRel]:
currently_observed_model = model_cls
field: Union["Field[Any, Any]", ForeignObjectRel, GenericForeignKey, None] = None
for field_part in field_parts:
@@ -378,19 +371,13 @@ def _resolve_field_from_parts(

field = currently_observed_model._meta.get_field(field_part)
if isinstance(field, RelatedField):
related_model = self.get_field_related_model_cls(field)
if related_model is None:
return None
currently_observed_model = related_model
currently_observed_model = self.get_field_related_model_cls(field)
model_name = currently_observed_model._meta.model_name
if model_name is not None and field_part == (model_name + "_id"):
field = self.get_primary_key_field(currently_observed_model)

if isinstance(field, ForeignObjectRel):
related_model = self.get_field_related_model_cls(field)
if related_model is None:
return None
currently_observed_model = related_model
currently_observed_model = self.get_field_related_model_cls(field)

# Guaranteed by `query.solve_lookup_type` before.
assert isinstance(field, (Field, ForeignObjectRel))
@@ -422,13 +409,10 @@ def solve_lookup_type(
if len(query_parts) == 1:
return [], [query_parts[0]], False

related_model = None
if isinstance(field, (RelatedField, ForeignObjectRel)):
related_model = self.get_field_related_model_cls(field)

if related_model is None:
if not isinstance(field, (RelatedField, ForeignObjectRel)):
return None

related_model = self.get_field_related_model_cls(field)
sub_query = Query(related_model).solve_lookup_type("__".join(query_parts[1:]))
entire_query_parts = [query_parts[0], *sub_query[1]]
return sub_query[0], entire_query_parts, sub_query[2]
@@ -460,8 +444,6 @@ def resolve_lookup_expected_type(self, ctx: MethodContext, model_cls: Type[Model
return AnyType(TypeOfAny.explicit)

field = self._resolve_field_from_parts(field_parts, model_cls)
if field is None:
return AnyType(TypeOfAny.from_error)

lookup_cls = None
if lookup_parts:
2 changes: 0 additions & 2 deletions mypy_django_plugin/transformers/models.py
Original file line number Diff line number Diff line change
@@ -448,8 +448,6 @@ def run_with_model_cls(self, model_cls: Type[Model]) -> None:
continue

related_model_cls = self.django_context.get_field_related_model_cls(relation)
if related_model_cls is None:
continue

try:
related_model_info = self.lookup_class_typeinfo_or_incomplete_defn_error(related_model_cls)
2 changes: 0 additions & 2 deletions mypy_django_plugin/transformers/querysets.py
Original file line number Diff line number Diff line change
@@ -63,8 +63,6 @@ def get_field_type_from_lookup(
lookup_field, ForeignObjectRel
):
related_model_cls = django_context.get_field_related_model_cls(lookup_field)
if related_model_cls is None:
return AnyType(TypeOfAny.from_error)
lookup_field = django_context.get_primary_key_field(related_model_cls)

field_get_type = django_context.get_field_get_type(helpers.get_typechecker_api(ctx), lookup_field, method=method)

0 comments on commit dd5cf7b

Please sign in to comment.