Skip to content

Python lexer does not consider .5 as float #1740

Closed

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.

Activity

  1. Liam-Stevens commented on Mar 24, 2021

    @Liam-Stevens
    Contributor

    We are a team of students from the University of Adelaide, we are currently working on this issue. Expect a pull request within the next month.

  2. linked a pull request that will close this issueFix python lexer parsing floats incorrectly #1768on May 2, 2021
  3. added this to the 2.9 milestone on May 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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