Skip to content

Commit

Permalink
Move get_function_hook to the bottom of the plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
delfick committed May 28, 2024
1 parent 64f6d7c commit 58acb62
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions extended_mypy_django_plugin/plugin/_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,27 @@ def run(self, ctx: AnalyzeTypeContext) -> MypyType:

return method(unbound_type=ctx.type)

@_hook.hook
class get_attribute_hook(Hook[AttributeContext, MypyType]):
"""
An implementation of the change found in
https://github.com/typeddjango/django-stubs/pull/2027
"""

def choose(self) -> bool:
return self.super_hook is resolve_manager_method

def run(self, ctx: AttributeContext) -> MypyType:
assert isinstance(ctx.api, TypeChecker)

type_checking = actions.TypeChecking(
self.store, api=ctx.api, lookup_info=self.plugin._lookup_info
)

return type_checking.extended_get_attribute_resolve_manager_method(
ctx, resolve_manager_method_from_instance=resolve_manager_method_from_instance
)

@_hook.hook
class get_function_hook(Hook[FunctionContext, MypyType]):
"""
Expand Down Expand Up @@ -311,24 +332,3 @@ def run(self, ctx: FunctionContext) -> MypyType:
return self.super_hook(ctx)

return ctx.default_return_type

@_hook.hook
class get_attribute_hook(Hook[AttributeContext, MypyType]):
"""
An implementation of the change found in
https://github.com/typeddjango/django-stubs/pull/2027
"""

def choose(self) -> bool:
return self.super_hook is resolve_manager_method

def run(self, ctx: AttributeContext) -> MypyType:
assert isinstance(ctx.api, TypeChecker)

type_checking = actions.TypeChecking(
self.store, api=ctx.api, lookup_info=self.plugin._lookup_info
)

return type_checking.extended_get_attribute_resolve_manager_method(
ctx, resolve_manager_method_from_instance=resolve_manager_method_from_instance
)

0 comments on commit 58acb62

Please sign in to comment.