Skip to content

Python counting is wrong with "" or '' #379

@geohot

Description

@geohot

Describe the bug
Python parser gets stuck in string state if it sees '' or ""

To Reproduce

Create tmp.py with this content and run scc tmp.py

a = ''

# comment
for i in range(10):
  print(i)

Expected behavior

This is the (wrong) output

───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
Python                       1         6        0         0        6          0
───────────────────────────────────────────────────────────────────────────────
Total                        1         6        0         0        6          0
───────────────────────────────────────────────────────────────────────────────

You get this if you change '' to str()

───────────────────────────────────────────────────────────────────────────────
Language                 Files     Lines   Blanks  Comments     Code Complexity
───────────────────────────────────────────────────────────────────────────────
Python                       1         6        2         1        3          1
───────────────────────────────────────────────────────────────────────────────
Total                        1         6        2         1        3          1
───────────────────────────────────────────────────────────────────────────────

Desktop (please complete the following information):
Mac OS, tried version in brew and master

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions