-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[mypyc]: support :s and :d in generate_format_ops #20534
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
base: master
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
15c0ea0 to
174af4a
Compare
| def g() -> str: | ||
| return FMT_D.format(400 + 20, "roll" + "up") | ||
| def h() -> str: | ||
| return FMT_S.format(400 + 20, "roll" + "up") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Python, {:s} appears to only support str values. There is no implicit conversion to strings:
>>> '{:s}'.format(2)
Traceback (most recent call last):
File "<python-input-7>", line 1, in <module>
'{:s}'.format(2)
~~~~~~~~~~~~~^^^
ValueError: Unknown format code 's' for object of type 'int'
I think we should have similar checks to support :s in a compatible way, or apply the optimization if the static type of the corresponding operand is builtins.str perhaps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, how's this?
Built on top of, and blocked by, #19970.
Will rebase once 19970 is merged and then mark this one as ready.