Skip to content

guess_lexer returns MIMELexer for Python code #1584

@amikrop

Description

@amikrop

pygments.lexers.guess_lexer seems to almost always return MIMELexer when given Python code, unless there is a shebang line at the start of the code. It would be really useful if a shebang wasn't necessary for it to guess correctly.
Python 3.9.0
pygments 2.7.1

fib.py:

def fib(n):
    if n < 1:
        return 0
    if n < 3:
        return 1
    return fib(n - 1) + fib(n - 2)

REPL:

>>> from pygments.lexers import guess_lexer
>>> guess_lexer(open('fib.py').read())
<pygments.lexers.MIMELexer>

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions