8000 [mypyc] Initial optimization for f-string through a str.join() specializer by 97littleleaf11 · Pull Request #10776 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

[mypyc] Initial optimization for f-string through a str.join() specializer #10776

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 8 commits into from
Jul 8, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix
  • Loading branch information
97littleleaf11 committed Jul 7, 2021
commit bfcf56abd9c62013f9145ab6e708d1b86f7f48af
7 changes: 4 additions & 3 deletions mypyc/irbuild/specialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ def split_braces(format_str: str) -> List[str]:
ret_list.append(tmp_str)
return ret_list


@specialize_function('join', str_rprimitive)
def translate_fstring(
builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Optional[Value]:
Expand All @@ -463,9 +464,9 @@ def translate_fstring(
if isinstance(item, StrExpr):
continue
elif isinstance(item, CallExpr):
if item.callee.name != 'format':
return None
if item.callee.expr.value != '{:{}}':
if (not isinstance(item.callee, MemberExpr)
or item.callee.name != 'format'
or item.callee.expr.value != '{:{}}'):
return None
if not isinstance(item.args[1], StrExpr) or item.args[1].value != '':
return None
Expand Down
0