Python source code not getting detected

Issue #1442 new
Amal Murali
created an issue

Thank you for the great work on this library! The issue I've discovered is that guess_lexer() is not finding this (among other snippets) as Python source code:

out=open('assignment.in', 'w').write

n = 300

out('%d\n'%n)
for i in range(1, n + 1):
    out(' '.join('%d'%(i * j) for j in range(1, n + 1)) + '\n')

Or any of these: - https://pastebin.com/raw/aKbNPSkT - https://pastebin.com/raw/Ubf9h0Ax - https://pastebin.com/raw/JsPsMTtQ

etc.

What can it detect as Python source code? I'm trying to understand why. Could anyone please shed some light on this problem?

Thanks!

Comments (2)

  1. Amal Murali reporter

    Is it because of this condition in lexers/python.py line 240?

        def analyse_text(text):
            return shebang_matches(text, r'pythonw?(2(\.\d)?)?') or \
                'import ' in text[:1000]
    
  2. Log in to comment