{"id":"f9ef33be42480b75","repo":"pypa/pip","slug":"no-lexer-for-filename-fn-r-found","errorCode":null,"errorMessage":"no lexer for filename {_fn!r} found","messagePattern":"no lexer for filename (.+?) found","errorType":"exception","errorClass":"ClassNotFound","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/pygments/lexers/__init__.py","lineNumber":227,"sourceCode":"        return matches[-1][0]\n\n\ndef get_lexer_for_filename(_fn, code=None, **options):\n    \"\"\"Get a lexer for a filename.\n\n    Return a `Lexer` subclass instance that has a filename pattern\n    matching `fn`. The lexer is given the `options` at its\n    instantiation.\n\n    Raise :exc:`pygments.util.ClassNotFound` if no lexer for that filename\n    is found.\n\n    If multiple lexers match the filename pattern, use their ``analyse_text()``\n    methods to figure out which one is more appropriate.\n    \"\"\"\n    res = find_lexer_class_for_filename(_fn, code)\n    if not res:\n        raise ClassNotFound(f'no lexer for filename {_fn!r} found')\n    return res(**options)\n\n\ndef get_lexer_for_mimetype(_mime, **options):\n    \"\"\"\n    Return a `Lexer` subclass instance that has `mime` in its mimetype\n    list. The lexer is given the `options` at its instantiation.\n\n    Will raise :exc:`pygments.util.ClassNotFound` if not lexer for that mimetype\n    is found.\n    \"\"\"\n    for modname, name, _, _, mimetypes in LEXERS.values():\n        if _mime in mimetypes:\n            if name not in _lexer_cache:\n                _load_lexers(modname)\n            return _lexer_cache[name](**options)\n    for cls in find_plugin_lexers():\n        if _mime in cls.mimetypes:","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/pygments/lexers/__init__.py#L209-L245","documentation":"Raised by get_lexer_for_filename when no lexer's filename glob pattern (builtin or plugin) matches the basename of the supplied filename. If multiple match, analyse_text breaks the tie; if none match, this is raised.","triggerScenarios":"get_lexer_for_filename('data.xyz') where .xyz isn't registered, or a file with no extension.","commonSituations":"Highlighting source for an exotic/custom extension; extension only covered by an uninstalled plugin; content-based detection needed instead.","solutions":["Use guess_lexer (content-based) or get_lexer_by_name with an explicit alias.","Register a plugin lexer whose filenames glob covers the extension.","Map known custom extensions to aliases yourself before calling pygments."],"exampleFix":"# before\nlex = get_lexer_for_filename('notes.xyz')\n# after\nlex = guess_lexer(text)  # or get_lexer_by_name('text')","handlingStrategy":"fallback","validationCode":"from pygments.lexers import get_lexer_for_filename, get_lexer_by_name, TextLexer\nfrom pygments.util import ClassNotFound\ndef lexer_for(fn, fallback='text'):\n    try:\n        return get_lexer_for_filename(fn)\n    except ClassNotFound:\n        return get_lexer_by_name(fallback)","typeGuard":null,"tryCatchPattern":"from pygments.util import ClassNotFound\nfrom pygments.lexers import TextLexer\ntry:\n    lex = get_lexer_for_filename(fn)\nexcept ClassNotFound:\n    lex = TextLexer()","preventionTips":["Maintain your own extension-to-alias map for custom file types.","Fall back to TextLexer for unknown extensions."],"tags":["pygments","lexer","filename","lookup"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}