Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python lexer does not consider .5 as float #1740

Closed
khoda81 opened this issue Mar 6, 2021 · 1 comment · Fixed by #1768
Closed

Python lexer does not consider .5 as float #1740

khoda81 opened this issue Mar 6, 2021 · 1 comment · Fixed by #1768
Labels
A-lexing area: changes to individual lexers good first issue Good for newcomers
Milestone

Comments

@khoda81
Copy link

khoda81 commented Mar 6, 2021

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.

@Anteru Anteru added good first issue Good for newcomers A-lexing area: changes to individual lexers labels Mar 6, 2021
@Liam-Stevens
Copy link
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.

@Anteru Anteru linked a pull request May 2, 2021 that will close this issue
@Anteru Anteru added this to the 2.9 milestone May 2, 2021
@Anteru Anteru closed this as completed May 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lexing area: changes to individual lexers good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants