Skip to content

ast: FormattedValue.conversion cannot be None #7810

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

Merged
merged 5 commits into from
May 9, 2022

Conversation

JelleZijlstra
Copy link
Member

In [4]: ast.dump(ast.parse('f"{x!r}"'))
Out[4]: "Module(body=[Expr(value=JoinedStr(values=[FormattedValue(value=Name(id='x', ctx=Load()), conversion=114)]))], type_ignores=[])"

In [5]: ast.dump(ast.parse('f"{x}"'))
Out[5]: "Module(body=[Expr(value=JoinedStr(values=[FormattedValue(value=Name(id='x', ctx=Load()), conversion=-1)]))], type_ignores=[])"

(On 3.9 but I don't think this has changed since 3.6.)

The stdlib also assumes this: https://github.com/python/cpython/blob/main/Lib/ast.py#L1211 (chr(None) doesn't work).

```
In [4]: ast.dump(ast.parse('f"{x!r}"'))
Out[4]: "Module(body=[Expr(value=JoinedStr(values=[FormattedValue(value=Name(id='x', ctx=Load()), conversion=114)]))], type_ignores=[])"

In [5]: ast.dump(ast.parse('f"{x}"'))
Out[5]: "Module(body=[Expr(value=JoinedStr(values=[FormattedValue(value=Name(id='x', ctx=Load()), conversion=-1)]))], type_ignores=[])"
```
(On 3.9 but I don't think this has changed since 3.6.)

The stdlib also assumes this: https://github.com/python/cpython/blob/main/Lib/ast.py#L1211 (`chr(None)` doesn't work).
@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

@JelleZijlstra JelleZijlstra marked this pull request as draft May 9, 2022 01:52
@github-actions

This comment has been minimized.

@hauntsaninja
Copy link
Collaborator

I think you might only need the allowlist on py39

@github-actions

This comment has been minimized.

@JelleZijlstra
Copy link
Member Author

I guess so, I wonder what changed in 3.9.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented May 9, 2022

Well 3.9 changing stuff is believable, the better question is what happened in 3.10 and the answer is Batuhan made things better: python/cpython#30467

@github-actions
Copy link
Contributor

github-actions bot commented May 9, 2022

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JelleZijlstra JelleZijlstra marked this pull request as ready for review May 9, 2022 02:20
@hauntsaninja hauntsaninja merged commit 5c13f8b into master May 9, 2022
@hauntsaninja hauntsaninja deleted the JelleZijlstra-patch-1 branch May 9, 2022 02:42
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