<commit_before>package com.jetbrains.python.validation;

import com.intellij.lang.ASTNode;
import com.intellij.lang.annotation.Annotation;
import com.intellij.psi.ResolveResult;
import com.jetbrains.python.PyHighlighter;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.psi.PyClass;
import com.jetbrains.python.psi.PyReferenceExpression;
import com.jetbrains.python.psi.resolve.PyResolveUtil;
import com.jetbrains.python.psi.impl.PyBuiltinCache;

/**
 * Marks built-in names.
 * User: dcheryasov
 * Date: Jan 10, 2009 12:17:15 PM
 */
public class PyBuiltinAnnotator extends PyAnnotator {
  @Override
  public void visitPyReferenceExpression(PyReferenceExpression node) {
    if (PyNames.UnderscoredNames.contains(node.getName())) {
      // things like __len__
      if (
        (node.getQualifier() != null) // foo.__len__
        || (PyResolveUtil.getConcealingParent(node) instanceof PyClass) // class Foo: ... __len__ = myLenImpl
      ) {
        final ASTNode astNode = node.getNode();
        if (astNode != null) {
          ASTNode tgt = astNode.findChildByType(PyTokenTypes.IDENTIFIER); // only the id, not all qualifiers subtree
          if (tgt != null) {
            Annotation ann = getHolder().createInfoAnnotation(tgt, null);
            ann.setTextAttributes(PyHighlighter.PY_PREDEFINED_USAGE);
          }
        }
      }
    }
    else if (node.getQualifier() == null) {
      // things like len()
      for (ResolveResult resolved : node.multiResolve(false)) { // things like constructors give multiple results
        if (PyBuiltinCache.hasInBuiltins(resolved.getElement())) {
          Annotation ann = getHolder().createInfoAnnotation(node, null);
          ann.setTextAttributes(PyHighlighter.PY_BUILTIN_NAME);
          break;
        }
      }
    }
  }

}<commit_msg>Classes that merely inherit from built-in classes are no more highlighted as built-in.<commit_after>package com.jetbrains.python.validation;

import com.intellij.lang.ASTNode;
import com.intellij.lang.annotation.Annotation;
import com.intellij.psi.ResolveResult;
import com.jetbrains.python.PyHighlighter;
import com.jetbrains.python.PyNames;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.psi.PyClass;
import com.jetbrains.python.psi.PyReferenceExpression;
import com.jetbrains.python.psi.resolve.PyResolveUtil;
import com.jetbrains.python.psi.impl.PyBuiltinCache;

/**
 * Marks built-in names.
 * User: dcheryasov
 * Date: Jan 10, 2009 12:17:15 PM
 */
public class PyBuiltinAnnotator extends PyAnnotator {
  @Override
  public void visitPyReferenceExpression(PyReferenceExpression node) {
    if (PyNames.UnderscoredNames.contains(node.getName())) {
      // things like __len__
      if (
        (node.getQualifier() != null) // foo.__len__
        || (PyResolveUtil.getConcealingParent(node) instanceof PyClass) // class Foo: ... __len__ = myLenImpl
      ) {
        final ASTNode astNode = node.getNode();
        if (astNode != null) {
          ASTNode tgt = astNode.findChildByType(PyTokenTypes.IDENTIFIER); // only the id, not all qualifiers subtree
          if (tgt != null) {
            Annotation ann = getHolder().createInfoAnnotation(tgt, null);
            ann.setTextAttributes(PyHighlighter.PY_PREDEFINED_USAGE);
          }
        }
      }
    }
    else if (node.getQualifier() == null) {
      // things like len()
      ResolveResult[] resolved = node.multiResolve(false); // constructors, etc give multiple results...
      if (resolved.length > 0) {
        if (PyBuiltinCache.hasInBuiltins(resolved[0].getElement())) { // ...but we only care about single-resolvers
          Annotation ann = getHolder().createInfoAnnotation(node, null);
          ann.setTextAttributes(PyHighlighter.PY_BUILTIN_NAME);
        }
      }
    }
  }

}
{'fraction_non_alphanumeric': 0.11064826868003125, 'fraction_numerical': 0.006769070554543088, 'mean_word_length': 3.221978021978022, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4940179', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1159, 'n_words': 236}