{"record":{"id":"7db72898fdaca455","repo":"pypa/pip","slug":"no-lexer-matching-the-text-found","errorCode":null,"errorMessage":"no lexer matching the text found","messagePattern":"no lexer matching the text found","errorType":"exception","errorClass":"ClassNotFound","httpStatus":null,"severity":"warning","filePath":"src/pip/_vendor/pygments/lexers/__init__.py","lineNumber":339,"sourceCode":"\n    # try to get a vim modeline first\n    ft = get_filetype_from_buffer(_text)\n\n    if ft is not None:\n        try:\n            return get_lexer_by_name(ft, **options)\n        except ClassNotFound:\n            pass\n\n    best_lexer = [0.0, None]\n    for lexer in _iter_lexerclasses():\n        rv = lexer.analyse_text(_text)\n        if rv == 1.0:\n            return lexer(**options)\n        if rv > best_lexer[0]:\n            best_lexer[:] = (rv, lexer)\n    if not best_lexer[0] or best_lexer[1] is None:\n        raise ClassNotFound('no lexer matching the text found')\n    return best_lexer[1](**options)\n\n\nclass _automodule(types.ModuleType):\n    \"\"\"Automatically import lexers.\"\"\"\n\n    def __getattr__(self, name):\n        info = LEXERS.get(name)\n        if info:\n            _load_lexers(info[0])\n            cls = _lexer_cache[info[1]]\n            setattr(self, name, cls)\n            return cls\n        if name in COMPAT:\n            return getattr(self, COMPAT[name])\n        raise AttributeError(name)\n\n","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/pygments/lexers/__init__.py#L321-L357","documentation":"Raised by guess_lexer() as a ClassNotFound when, after iterating every lexer class via _iter_lexerclasses() and calling analyse_text(), the best score is 0.0 or no lexer was assigned (line 338-339). No lexer's content heuristics returned a positive value and no vim modeline resolved either.","triggerScenarios":"Calling guess_lexer() on very short, ambiguous, or binary-decoded text that no lexer's analyse_text() can positively identify; text that is valid but extremely generic (plain ASCII with no distinguishing tokens).","commonSituations":"Auto-detecting a language for a one-line file or a file full of whitespace/numbers; feeding text that decodes ambiguously via guess_decode(); a buffer where every analyse_text returns 0.0 by default.","solutions":["Provide more representative sample text — analyse_text heuristics need enough content to exceed the 0.0 floor.","Fall back to a default lexer such as get_lexer_by_name('text') when detection fails.","If you know the language, call get_lexer_by_name() directly instead of guessing."],"exampleFix":"// before\nlexer = guess_lexer(short_or_empty_text)\n\n// after\nfrom pygments.lexers import guess_lexer, get_lexer_by_name\nfrom pygments.util import ClassNotFound\ntry:\n    lexer = guess_lexer(text)\nexcept ClassNotFound:\n    lexer = get_lexer_by_name('text')","handlingStrategy":"fallback","validationCode":"from pygments.lexers import _iter_lexerclasses\ndef best_score(text):\n    scores = [(lx.analyse_text(text), lx) for lx in _iter_lexerclasses()]\n    scores.sort(key=lambda t: t[0])\n    return scores[-1]\ndef is_detectable(text):\n    return best_score(text)[0] > 0.0","typeGuard":null,"tryCatchPattern":"from pygments.lexers import guess_lexer, get_lexer_by_name\nfrom pygments.util import ClassNotFound\ntry:\n    lexer = guess_lexer(text)\nexcept ClassNotFound:\n    lexer = get_lexer_by_name('text')","preventionTips":["Supply a sufficiently large, representative text sample to analyse_text heuristics.","Default to a known lexer (e.g. 'text') when content detection fails rather than letting it raise."],"tags":["pygments","lexer","text-analysis","guess","class-not-found"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}