Skip to content

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.

3 participants