private static PyType getTypeByControlFlow(@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, context);
      // null means empty set of possible types, Ref(null) means Any
      final @Nullable Ref<PyType> combinedType = StreamEx.of(defs)
        .map(instr -> {
          if (instr instanceof ReadWriteInstruction readWriteInstruction) {
            return readWriteInstruction.getType(context, anchor);
          }
          if (instr instanceof ConditionalInstruction conditionalInstruction) {
             if (context.getType((PyTypedElement)conditionalInstruction.getCondition()) instanceof PyNarrowedType narrowedType) {
               PyExpression[] arguments = narrowedType.getOriginal().getArguments();
               if (arguments.length > 0) {
                 var firstArgument = arguments[0];
                 if (firstArgument instanceof PyReferenceExpression) {
                   return PyTypeAssertionEvaluator.createAssertionType(
                     context.getType(firstArgument),
                     narrowedType.getNarrowedType(),
                     conditionalInstruction.getResult() ^ narrowedType.getNegated(),
                     false,
                     context,
                     null);
                 }
               }
             }
          }
          return null;
        })
        .nonNull()
        .collect(PyTypeUtil.toUnionFromRef());
      return Ref.deref(combinedType);
    }
    catch (PyDefUseUtil.InstructionNotFoundException ignored) {
    }
    return null;
  }
private static PyType getTypeByControlFlow(@NotNull String name,
                                             @NotNull TypeEvalContext context,
                                             @NotNull PyExpression anchor,
                                             @NotNull ScopeOwner scopeOwner)