Skip to content

pyparsing.python_style_comment.suppress() does not work with multi-line strings #421

@Andi144

Description

@Andi144

Consider this MWE:

import pyparsing

code = '"""this is a\nmulti-line  # not an actual comment\nstring"""'

comment_filter = pyparsing.python_style_comment.suppress()
print(comment_filter.transform_string(code))

where code is a valid Python program that contains only a single multi-line string:

"""this is a
multi-line  # not an actual comment
string"""

This string contains a # character, but since it is within the string, it should not be treated as a comment. pyparsing does so, however. Output of the above MWE:

"""this is a
multi-line
string"""

where # not an actual comment has been incorrectly removed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions