Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add f-strings to label visitor#142

Merged
KevinHock merged 1 commit into
python-security:masterfrom
bcaller:bc-f-string
Jul 13, 2018
Merged

Add f-strings to label visitor#142
KevinHock merged 1 commit into
python-security:masterfrom
bcaller:bc-f-string

Conversation

@bcaller
Copy link
Copy Markdown
Collaborator

@bcaller bcaller commented Jul 12, 2018

Node types FormattedValue and JoinedStr were added in python 3.6.

@bcaller
Copy link
Copy Markdown
Collaborator Author

bcaller commented Jul 12, 2018

#14

@KevinHock KevinHock self-requested a review July 13, 2018 01:53
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

2 participants