PyType (@NotNull String name, @NotNull TypeEvalContext context, @NotNull PyExpression anchor, @NotNull ScopeOwner scopeOwner) { final PyAugAssignmentStatement augAssignment = PsiTreeUtil.getParentOfType(anchor, PyAugAssignmentStatement.class); final PyElement element = augAssignment != null ? augAssignment : anchor; try { final List<Instruction> defs = PyDefUseUtil.getLatestDefs(scopeOwner, name, element, true, false); // null means empty set of possible types, Ref(null) means Any final @Nullable Ref<PyType> combinedType = StreamEx.of(defs) .select(ReadWriteInstruction.class) .map(instr -> instr.getType(context, anchor)) .collect(PyTypeUtil.toUnionFromRef()); return Ref.deref(combinedType); } catch (PyDefUseUtil.InstructionNotFoundException ignored) { } return null; }