Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove generic argument of django.db.models.lookups.Lookup #2205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

flaeppe
Copy link
Member

@flaeppe flaeppe commented Jun 4, 2024

I might be missing something obvious here but I don't see what purpose the generic argument has or what it intends to control.

I might be missing something obvious here but I don't see what purpose
the generic argument has or what it intends to control.
@flaeppe
Copy link
Member Author

flaeppe commented Jun 4, 2024

Aha, I think I found it under mypy_django_plugin.django.context.resolve_lookup_expected_type in the Mypy plugin:

for lookup_base in helpers.iter_bases(lookup_info):
if lookup_base.args and isinstance(lookup_base.args[0], Instance):
lookup_type: MypyType = lookup_base.args[0]
# if it's Field, consider lookup_type a __get__ of current field
if isinstance(lookup_type, Instance) and lookup_type.type.fullname == fullnames.FIELD_FULLNAME:
field_info = helpers.lookup_class_typeinfo(helpers.get_typechecker_api(ctx), field.__class__)
if field_info is None:
return AnyType(TypeOfAny.explicit)
lookup_type = helpers.get_private_descriptor_type(
field_info, "_pyi_private_get_type", is_nullable=field.null
)
return lookup_type

But I currently think it looks a bit off with a generic argument on the Lookup type. I'm guessing it instead should always prefer to be based on the "get type" of the field.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant