mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-09 21:46:43 +08:00
additional defer() to offset the effect of using the type before decl… (#424)
* additional defer() to offset the effect of using the type before declaring * linter fix * linter fix * linter fix * test case Co-authored-by: Kacper Szmigiel <szmigielkacper@gmai.com>
This commit is contained in:
@@ -343,6 +343,7 @@ def copy_method_to_another_class(ctx: ClassDefContext, self_type: Instance,
|
||||
arguments = []
|
||||
bound_return_type = semanal_api.anal_type(method_type.ret_type,
|
||||
allow_placeholder=True)
|
||||
|
||||
assert bound_return_type is not None
|
||||
|
||||
if isinstance(bound_return_type, PlaceholderNode):
|
||||
@@ -352,6 +353,10 @@ def copy_method_to_another_class(ctx: ClassDefContext, self_type: Instance,
|
||||
method_type.arg_types[1:],
|
||||
method_node.arguments[1:]):
|
||||
bound_arg_type = semanal_api.anal_type(arg_type, allow_placeholder=True)
|
||||
if bound_arg_type is None and not semanal_api.final_iteration:
|
||||
semanal_api.defer()
|
||||
return
|
||||
|
||||
assert bound_arg_type is not None
|
||||
|
||||
if isinstance(bound_arg_type, PlaceholderNode):
|
||||
|
||||
@@ -335,3 +335,25 @@
|
||||
objects = MyManager()
|
||||
class ChildUser(models.Model):
|
||||
objects = MyManager()
|
||||
|
||||
- case: custom_manager_annotate_method_before_type_declaration
|
||||
main: |
|
||||
from myapp.models import ModelA, ModelB, ManagerA
|
||||
reveal_type(ModelA.objects) # N: Revealed type is 'myapp.models.ModelA_ManagerA1[myapp.models.ModelA]'
|
||||
reveal_type(ModelA.objects.do_something) # N: Revealed type is 'def (other_obj: myapp.models.ModelB) -> builtins.str'
|
||||
installed_apps:
|
||||
- myapp
|
||||
files:
|
||||
- path: myapp/__init__.py
|
||||
- path: myapp/models.py
|
||||
content: |
|
||||
from django.db import models
|
||||
class ManagerA(models.Manager):
|
||||
def do_something(self, other_obj: "ModelB") -> str:
|
||||
return 'test'
|
||||
class ModelA(models.Model):
|
||||
title = models.TextField()
|
||||
objects = ManagerA()
|
||||
class ModelB(models.Model):
|
||||
movie = models.TextField()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user