-
-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: str.join constant folding support (and bytes.join for mypyc) #19884
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
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
e84c21c
to
84f705a
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
elif isinstance(expr, CallExpr) and isinstance(callee := expr.callee, MemberExpr): | ||
folded_callee = constant_fold_expr(builder, callee.expr) | ||
|
||
# builtins.str methods |
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.
We can constant fold quite a lot of cases for builtins without too much code. I have an idea for how to implement this cleanly but that's outside the scope of this PR.
This comment has been minimized.
This comment has been minimized.
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
I don't see any reason for this test to not fail based on the code changes. I think I might be using TupleType incorrectly here, or accessing the type in a less-than-optimal way. Any advice here would be appreciated. |
Diff from mypy_primer, showing the effect of this PR on open source code: graphql-core (https://github.com/graphql-python/graphql-core)
- version: 1.19.0+dev.19697af9051707b4db55bc2d5301436d872f452c
+ version: 1.19.0+dev.9ea11f958df51f70158064260d71ac32dfedf771
|
Intent:
Mypyc can currently handle constant folding of f-strings, but mypy itself cannot.
Changes:
str.join
expressions. It is a critical first step for implementing f-string support, which will come in a follow-up PR.I can break those changes up if you'd prefer.