Skip to content

Python docstrings mishandle apostrophes  #246

@dbaggerman

Description

@dbaggerman

Describe the bug
Python docstrings containing an apostrophe end up in a weird state, continuing the docstring parsing beyond the end of the docstring and then ending up in a string state waiting for a closing single quote / apostrophe.

To Reproduce

#!/usr/bin/env python3

"""
Docstrings containing an apostrophe (') are handled incorrectly
The line above is counted as code despite being in the middle of a docstring.
The end of docstring flag seems to be changed to an apostrophe,
which means the next line will not exit the docstring.
"""
# Code containing single quotes will exit the docstring,
# but presuming the quotes are balanced the second
# quote will put us in string scanning mode.
if __name__ == '__main__':
    print('Hello, World!')
# Not counted as a comment

# ^ Not counted as a blank line
# Break out of string scanner with unbalanced single quote: '
    exit(0)

Expected behavior
Apostrophes / single quotes inside a docstring don't interrupt docstring parsing.

Desktop (please complete the following information):

  • Version 3.0

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