diff options
Diffstat (limited to 'pygments/__init__.py')
-rw-r--r-- | pygments/__init__.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/pygments/__init__.py b/pygments/__init__.py index 52ff035d..1c107f33 100644 --- a/pygments/__init__.py +++ b/pygments/__init__.py @@ -39,9 +39,9 @@ def lex(code, lexer): try: return lexer.get_tokens(code) except TypeError as err: - if (isinstance(err.args[0], str) and - ('unbound method get_tokens' in err.args[0] or - 'missing 1 required positional argument' in err.args[0])): + # Heuristic to catch a common mistake. + from pygments.lexer import RegexLexer + if isinstance(lexer, type) and issubclass(lexer, RegexLexer): raise TypeError('lex() argument must be a lexer instance, ' 'not a class') raise @@ -63,9 +63,9 @@ def format(tokens, formatter, outfile=None): # pylint: disable=redefined-builti else: formatter.format(tokens, outfile) except TypeError as err: - if (isinstance(err.args[0], str) and - ('unbound method format' in err.args[0] or - 'missing 1 required positional argument' in err.args[0])): + # Heuristic to catch a common mistake. + from pygments.formatter import Formatter + if isinstance(formatter, type) and issubclass(formatter, Formatter): raise TypeError('format() argument must be a formatter instance, ' 'not a class') raise @@ -80,4 +80,3 @@ def highlight(code, lexer, formatter, outfile=None): it is returned as a string. """ return format(lex(code, lexer), formatter, outfile) - |