Skip to content

Commit

Permalink
Fix type annotation for RegisterLookupMixin.class_lookups
Browse files Browse the repository at this point in the history
The existing annotation (`list[dict[Any, Any]]`) is incorrect, leading
to errors in any code that actually uses this attribute.

The proper type is evident from the code in Django that registers
class lookups[^1]:

    def register_class_lookup(cls, lookup, lookup_name=None):
        if lookup_name is None:
            lookup_name = lookup.lookup_name
        if "class_lookups" not in cls.__dict__:
            cls.class_lookups = {}
        cls.class_lookups[lookup_name] = lookup
        cls._clear_cached_class_lookups()
        return lookup

[^1]: https://github.com/django/django/blob/50e95ad5367a4a93f94a66a645f9c126f0609f0a/django/db/models/query_utils.py#L296
  • Loading branch information
avoronov-box committed Feb 23, 2024
1 parent 7564f79 commit 37a8026
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion django-stubs/db/models/query_utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DeferredAttribute:
_R = TypeVar("_R", bound=type)

class RegisterLookupMixin:
class_lookups: list[dict[Any, Any]]
class_lookups: dict[str, Any]
lookup_name: str
@classmethod
def get_lookups(cls) -> dict[str, Any]: ...
Expand Down

0 comments on commit 37a8026

Please sign in to comment.