mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-07 04:34:29 +08:00
some cleanups
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
from typing import Optional, Callable
|
from typing import Optional, Callable
|
||||||
|
|
||||||
from mypy.nodes import SymbolTableNode, MDEF, Var
|
from mypy.nodes import Var, MDEF, SymbolTableNode
|
||||||
from mypy.plugin import Plugin, FunctionContext
|
from mypy.plugin import Plugin, FunctionContext
|
||||||
from mypy.types import Type, CallableType, TypeOfAny, AnyType, Instance
|
from mypy.types import Type, CallableType, Instance
|
||||||
|
|
||||||
|
|
||||||
def set_related_fields(ctx: FunctionContext) -> Type:
|
def set_related_name_manager_for_foreign_key(ctx: FunctionContext) -> Type:
|
||||||
if 'related_name' not in ctx.context.arg_names:
|
if 'related_name' not in ctx.context.arg_names:
|
||||||
return ctx.default_return_type
|
return ctx.default_return_type
|
||||||
|
|
||||||
@@ -23,8 +23,8 @@ def set_related_fields(ctx: FunctionContext) -> Type:
|
|||||||
related_var = Var(related_name,
|
related_var = Var(related_name,
|
||||||
queryset_type)
|
queryset_type)
|
||||||
related_var.info = queryset_type.type
|
related_var.info = queryset_type.type
|
||||||
|
referred_to.type.names[related_name] = SymbolTableNode(MDEF, related_var,
|
||||||
referred_to.type.names[related_name] = SymbolTableNode(MDEF, related_var)
|
plugin_generated=True)
|
||||||
return ctx.default_return_type
|
return ctx.default_return_type
|
||||||
|
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ class RelatedFieldsPlugin(Plugin):
|
|||||||
def get_function_hook(self, fullname: str
|
def get_function_hook(self, fullname: str
|
||||||
) -> Optional[Callable[[FunctionContext], Type]]:
|
) -> Optional[Callable[[FunctionContext], Type]]:
|
||||||
if fullname == 'django.db.models.fields.related.ForeignKey':
|
if fullname == 'django.db.models.fields.related.ForeignKey':
|
||||||
return set_related_fields
|
return set_related_name_manager_for_foreign_key
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
[mypy]
|
[mypy]
|
||||||
plugins =
|
plugins =
|
||||||
mypy_django_plugin.plugins.postgres_fields,
|
mypy_django_plugin.plugins.postgres_fields,
|
||||||
mypy_django_plugin.plugins.related_fields
|
mypy_django_plugin.plugins.related_fields
|
||||||
|
|||||||
@@ -23,6 +23,4 @@ class User(models.Model):
|
|||||||
user = User()
|
user = User()
|
||||||
reveal_type(user.members) # E: Revealed type is 'builtins.list[builtins.int*]'
|
reveal_type(user.members) # E: Revealed type is 'builtins.list[builtins.int*]'
|
||||||
reveal_type(user.members_as_text) # E: Revealed type is 'builtins.list[builtins.str*]'
|
reveal_type(user.members_as_text) # E: Revealed type is 'builtins.list[builtins.str*]'
|
||||||
[out]
|
[out]
|
||||||
|
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ class DjangoTestSuite(DataSuite):
|
|||||||
files = [
|
files = [
|
||||||
'check-model-fields.test',
|
'check-model-fields.test',
|
||||||
'check-postgres-fields.test',
|
'check-postgres-fields.test',
|
||||||
'check-model-relations.test'
|
'check-model-relations.test',
|
||||||
]
|
]
|
||||||
data_prefix = str(TEST_DATA_DIR)
|
data_prefix = str(TEST_DATA_DIR)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user