move to plugin common api, move to new functioncontext api

This commit is contained in:
Maxim Kurnikov
2018-12-19 02:41:28 +03:00
parent c9ad40d7e3
commit 094b8421ab
8 changed files with 46 additions and 308 deletions

View File

@@ -3,9 +3,9 @@ from mypy.types import Type
def determine_type_of_array_field(ctx: FunctionContext) -> Type:
if 'base_field' not in ctx.arg_names:
if 'base_field' not in ctx.callee_arg_names:
return ctx.default_return_type
base_field_arg_type = ctx.arg_types[ctx.arg_names.index('base_field')][0]
base_field_arg_type = ctx.arg_types[ctx.callee_arg_names.index('base_field')][0]
return ctx.api.named_generic_type(ctx.context.callee.fullname,
args=[base_field_arg_type.type.names['__get__'].type.ret_type])

View File

@@ -52,15 +52,6 @@ class ModelClassInitializer(metaclass=ABCMeta):
raise NotImplementedError()
def add_new_var_node_to_class(class_type: TypeInfo, name: str, typ: Instance) -> None:
var = Var(name=name, type=typ)
var.info = typ.type
var._fullname = class_type.fullname() + '.' + name
var.is_inferred = True
var.is_initialized_in_class = True
class_type.names[name] = SymbolTableNode(MDEF, var)
def iter_over_assignments(klass: ClassDef) -> Iterator[Tuple[Lvalue, Expression]]:
for stmt in klass.defs.body:
if not isinstance(stmt, AssignmentStmt):

View File

@@ -19,15 +19,15 @@ def fill_typevars_with_any(instance: Instance) -> Type:
def get_valid_to_value_or_none(ctx: FunctionContext) -> Optional[Instance]:
api = cast(TypeChecker, ctx.api)
if 'to' not in ctx.arg_names:
if 'to' not in ctx.callee_arg_names:
# shouldn't happen, invalid code
api.msg.fail(f'to= parameter must be set for {ctx.context.callee.fullname}',
context=ctx.context)
return None
arg_type = ctx.arg_types[ctx.arg_names.index('to')][0]
arg_type = ctx.arg_types[ctx.callee_arg_names.index('to')][0]
if not isinstance(arg_type, CallableType):
to_arg_expr = ctx.args[ctx.arg_names.index('to')][0]
to_arg_expr = ctx.args[ctx.callee_arg_names.index('to')][0]
if not isinstance(to_arg_expr, StrExpr):
# not string, not supported
return None