Search in sources :

Example 6 with DictType

use of org.yinwang.pysonar.types.DictType in project pysonar2 by yinwang0.

the class TypeInferencer method bind.

public void bind(@NotNull State s, Node target, @NotNull Type rvalue, Binding.Kind kind) {
    if (target instanceof Name) {
        bind(s, (Name) target, rvalue, kind);
    } else if (target instanceof Tuple) {
        bind(s, ((Tuple) target).elts, rvalue, kind);
    } else if (target instanceof PyList) {
        bind(s, ((PyList) target).elts, rvalue, kind);
    } else if (target instanceof Attribute) {
        setAttr(((Attribute) target), s, rvalue);
    } else if (target instanceof Subscript) {
        Subscript sub = (Subscript) target;
        Type sliceType = sub.slice == null ? null : visit(sub.slice, s);
        Type valueType = visit(sub.value, s);
        if (valueType instanceof ListType) {
            ListType t = (ListType) valueType;
            t.setElementType(UnionType.union(t.eltType, rvalue));
        } else if (valueType instanceof DictType) {
            DictType t = (DictType) valueType;
            if (sliceType != null) {
                t.setKeyType(UnionType.union(t.keyType, sliceType));
            }
            t.setValueType(UnionType.union(t.valueType, rvalue));
        }
    } else if (target != null) {
        addWarningToNode(target, "invalid location for assignment");
    }
}
Also used : ClassType(org.yinwang.pysonar.types.ClassType) ListType(org.yinwang.pysonar.types.ListType) DictType(org.yinwang.pysonar.types.DictType) InstanceType(org.yinwang.pysonar.types.InstanceType) Type(org.yinwang.pysonar.types.Type) UnionType(org.yinwang.pysonar.types.UnionType) TupleType(org.yinwang.pysonar.types.TupleType) FunType(org.yinwang.pysonar.types.FunType) ModuleType(org.yinwang.pysonar.types.ModuleType) ListType(org.yinwang.pysonar.types.ListType) DictType(org.yinwang.pysonar.types.DictType)

Aggregations

ClassType (org.yinwang.pysonar.types.ClassType)6 DictType (org.yinwang.pysonar.types.DictType)6 FunType (org.yinwang.pysonar.types.FunType)6 InstanceType (org.yinwang.pysonar.types.InstanceType)6 ListType (org.yinwang.pysonar.types.ListType)6 ModuleType (org.yinwang.pysonar.types.ModuleType)6 TupleType (org.yinwang.pysonar.types.TupleType)6 Type (org.yinwang.pysonar.types.Type)6 UnionType (org.yinwang.pysonar.types.UnionType)6 NotNull (org.jetbrains.annotations.NotNull)5 ArrayList (java.util.ArrayList)2 CallStackEntry (org.yinwang.pysonar.CallStackEntry)1 State (org.yinwang.pysonar.State)1