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

Failure to parse f-strings when field has = at the end #115

Open
Ark-kun opened this issue Sep 13, 2024 · 0 comments
Open

Failure to parse f-strings when field has = at the end #115

Ark-kun opened this issue Sep 13, 2024 · 0 comments

Comments

@Ark-kun
Copy link

Ark-kun commented Sep 13, 2024

Fails when f-string field has = at the end:

f"aaaa {sys.version_info=} bbb"
  File "pasta/base/annotate.py", line 1537, in visit_FormattedValue
    self.attr(
  File "pasta/base/annotate.py", line 1864, in attr
    attr_parts.append(self.token(attr_val))
                      ^^^^^^^^^^^^^^^^^^^^
  File "pasta/base/annotate.py", line 1774, in token
    raise AnnotationError(
pasta.base.annotate.AnnotationError: Expected '!' but found '='
line 1: sys_version=} is inconsistent with {sys.version_info=}. "

https://docs.python.org/3/reference/lexical_analysis.html#formatted-string-literals

When the equal sign '=' is provided, the output will have the expression text, the '=' and the evaluated value. Spaces after the opening brace '{', within the expression and after the '=' are all retained in the output. By default, the '=' causes the repr() of the expression to be provided, unless there is a format specified. When a format is specified it defaults to the str() of the expression unless a conversion '!r' is declared.

Added in version 3.8: The equal sign '='.

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

No branches or pull requests

1 participant