boolean (@NotNull PyTargetExpression target, @NotNull TypeEvalContext context) { final ScopeOwner scopeOwner = ScopeUtil.getScopeOwner(target); final String name = target.getName(); if (scopeOwner == null || name == null) { return false; } if (!target.isQualified()) { if (hasInlineAnnotation(target)) { return true; } StreamEx<PyTargetExpression> candidates = null; if (context.maySwitchToAST(target)) { final Scope scope = ControlFlowCache.getScope(scopeOwner); candidates = StreamEx.of(scope.getNamedElements(name, false)).select(PyTargetExpression.class); } // Unqualified target expression in either class or module else if (scopeOwner instanceof PyFile) { candidates = StreamEx.of(((PyFile)scopeOwner).getTopLevelAttributes()).filter(t -> name.equals(t.getName())); } else if (scopeOwner instanceof PyClass) { candidates = StreamEx.of(((PyClass)scopeOwner).getClassAttributes()).filter(t -> name.equals(t.getName())); } if (candidates != null) { return candidates.anyMatch(PyAnnotateVariableTypeIntention::hasInlineAnnotation); } } else if (isInstanceAttribute(target, context)) { // Set isDefinition=true to start searching right from the class level. final List<PyTargetExpression> classLevelDefinitions = findClassLevelDefinitions(target, context); return ContainerUtil.exists(classLevelDefinitions, PyAnnotateVariableTypeIntention::hasInlineAnnotation); } return false; }