Commits

Domen Kožar committed 2568865

get_lexer_by_name: handle edge case when _alias is None

  • Participants
  • Parent commits 79a9848

Comments (0)

Files changed (2)

File pygments/lexers/__init__.py

     """
     Get a lexer by an alias.
     """
+    if not _alias:
+        raise ClassNotFound('no lexer for alias %r found' % _alias)
+
     # lookup builtin lexers
     for module_name, name, aliases, _, _ in LEXERS.itervalues():
         if _alias in aliases:

File tests/test_basic_api.py

 from pygments.token import _TokenType, Text
 from pygments.lexer import RegexLexer
 from pygments.formatters.img import FontNotFound
-from pygments.util import BytesIO, StringIO, bytes, b
+from pygments.util import BytesIO, StringIO, bytes, b, ClassNotFound
 
 import support
 
         for mimetype in mimetypes:
             assert cls == lexers.get_lexer_for_mimetype(mimetype).__class__.__name__
 
+    try:
+        lexers.get_lexer_by_name(None)
+    except ClassNotFound:
+        pass
+    else:
+        raise Exception
+
 
 def test_formatter_public_api():
     ts = list(lexers.PythonLexer().get_tokens("def f(): pass"))