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

Add f-strings to label visitor #142

Merged
merged 1 commit into from
Jul 13, 2018

Conversation

bcaller
Copy link
Collaborator

@bcaller bcaller commented Jul 12, 2018

Node types FormattedValue and JoinedStr were added in python 3.6.

@bcaller
Copy link
Collaborator Author

bcaller commented Jul 12, 2018

#14

Copy link
Collaborator

@KevinHock KevinHock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚢

def visit_FormattedValue(self, node):
self.result += '{'
self.visit(node.value)
self.result += {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe add a comment for the formatting

self.result += {
   -1: '',     # no formatting
   97: '!a',   # ascii formatting
   114: '!r',  # repr formatting
   115: '!s',  # string formatting
}[node.conversion]

self.result += "'"

def visit_FormattedValue(self, node):
self.result += '{'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe add abstract grammar docstrings, I have started to do this recently.

e.g.

"""
    JoinedStr(expr* values)
"""
"""
    FormattedValue(expr value, int? conversion, expr? format_spec)
"""

Node types FormattedValue and JoinedStr were added in python 3.6.
@bcaller
Copy link
Collaborator Author

bcaller commented Jul 13, 2018

Comments added as requested.

@KevinHock KevinHock merged commit e692581 into python-security:master Jul 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants