Skip to content

Python lexer does not consider .5 as float #1740

@khoda81

Description

@khoda81

In python floats are sometimes written as fractions where decimal part is not written for example:

a = .3 # instead of 0.3

But seems like pygments does not consider them as float, considers a dot (operator) and a number.

Code to reproduce:

from pygments import lex
from pygments.lexers.python import PythonLexer
from pygments.token import Number as Number

content = "a = .5"

lineno = 0
for token in lex(content, PythonLexer()):
    print(token)

Results:

(Token.Name, 'a')
(Token.Text, ' ')
(Token.Operator, '=')
(Token.Text, ' ')
(Token.Operator, '.')
(Token.Literal.Number.Integer, '5')
(Token.Text, '\n')

Interestingly does consider 5. as float.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lexingarea: changes to individual lexersgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions