mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-12 06:51:53 +08:00
support for models.Model.objects, abstract mixins
This commit is contained in:
@@ -1,25 +1,14 @@
|
||||
from typing import Optional, Callable
|
||||
|
||||
from mypy.plugin import Plugin, FunctionContext
|
||||
from mypy.plugin import FunctionContext
|
||||
from mypy.types import Type
|
||||
|
||||
from mypy_django_plugin import helpers
|
||||
|
||||
|
||||
def determine_type_of_array_field(ctx: FunctionContext) -> Type:
|
||||
assert 'base_field' in ctx.context.arg_names
|
||||
base_field_arg_index = ctx.context.arg_names.index('base_field')
|
||||
base_field_arg_type = ctx.arg_types[base_field_arg_index][0]
|
||||
signature = helpers.get_call_signature_or_none(ctx)
|
||||
if signature is None:
|
||||
return ctx.default_return_type
|
||||
|
||||
_, base_field_arg_type = signature['base_field']
|
||||
return ctx.api.named_generic_type(ctx.context.callee.fullname,
|
||||
args=[base_field_arg_type.type.names['__get__'].type.ret_type])
|
||||
|
||||
|
||||
class PostgresFieldsPlugin(Plugin):
|
||||
def get_function_hook(self, fullname: str
|
||||
) -> Optional[Callable[[FunctionContext], Type]]:
|
||||
if fullname == 'django.contrib.postgres.fields.array.ArrayField':
|
||||
return determine_type_of_array_field
|
||||
return None
|
||||
|
||||
|
||||
def plugin(version):
|
||||
return PostgresFieldsPlugin
|
||||
|
||||
Reference in New Issue
Block a user