-
Notifications
You must be signed in to change notification settings - Fork 92
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
Can Bowler rename the variable in the format string literals? #87
Comments
The first part -- renaming the variable within an f-string -- is not currently supported, but I would be glad to review a PR if you feel like adding it. @jreese is that second part a bug, renaming the kwarg in a call? The docs are unclear at https://pybowler.io/docs/api-selectors#select-var |
That looks like a side effect of the way the As for modifying contents of string literals, we would need to add support for parsing all string literals for f-string-like syntax, which itself would require more than what lib2to3 can offer. I believe something like typed_ast is capable of doing this, but I'm not certain, and at the very least would require a fair amount of work to fit this second method of parsing and transformations into the Bowler workflow. |
I found this issue about "f-strings are parsed just as regular strings" on python bug tracker, and it is not resolved yet. Since the mechanism of Bowler's |
We could either hack around this in Bowler while we use fissix (lib2to3) or wait until Bowler2 uses LibCST, at which point we can have first-party support for using them. I'm inclined to wait, mainly because I've tried to upstream things to lib2to3 before and it didn't go well. |
@thatch Thanks for your update. |
Any progress or plans on Bowler2. @sangwoo-joh Did you manage to rename vars in fstrings some other way? |
@Omar-Elrefaei |
If you have shareable code that renames variables, I would be in your debt 😳. |
@Omar-Elrefaei It is true that libcst can parse the f-strings, but it has a tricky thing too: it does not provide APIs to decide whether to visit the child attributes or not; only for child nodes. Because of this lack, recklessly using |
@sangwoo-joh Appreciate it. ❤️ |
Hi.
I have some code that uses format string literals and
.format()
like below:I want to rename the variable name
bar
tobar_new
so therename.py
script is ready:I hope Bowler recognize the placeholder in string literal,
{bar}
, but it wasn't:I want Bowler to rename
f'bar is {bar}, not {zar}'
→f'bar is {bar_new}, not {zar}'
.format(bar=bar, zar=zar)
→'.format(bar=bar_new, zar=zar)
and this is what exactly the Refactor → Rename function does in PyCharm.
Is there a way to refactor my code like this?
Thank you for your great tool.
The text was updated successfully, but these errors were encountered: