Skip to content
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

refactoring can change the value of strings (fstring formatting) #197

Closed
ReinhardtJ opened this issue Feb 22, 2022 · 1 comment
Closed
Labels
bug Something isn't working next release This will be fixed in next release

Comments

@ReinhardtJ
Copy link

Issue description or question

I'm currently writing a parser for a certain file format by using regexes. This is my code

tag_pattern = r':([0-9]{2}[A-Z]):'
qualifier_pattern = r':([A-Z]{4})\/\/'
tag_and_qualifier_pattern = f'{tag_pattern}{qualifier_pattern}'

on the line with qualifier_pattern, it suggests me

  • Inline variable that is only used once(inline-variable)
  • Simplify unnecessary nesting, casting and constant values in f-strings(simplify-fstring-formatting)

As soon as I apply, the code becomes

tag_pattern = r':([0-9]{2}[A-Z]):'
tag_and_qualifier_pattern = f'{tag_pattern}:([A-Z]{4})\\/\\/'

Firstly, the curly braces around the 4 won't appear in the string anymore, secondly, it adds additional escape-backslashes in front of the already existing backslashes (probably beacuse it detects that qualifier_pattern is an r-string. I usually use r-strings for regex-patterns to prevent accidental string formatting, even if it is not needed in this example. Ideally, it shouldn't matter of course).

Sourcery Version

0.10.1.

Code editor or IDE name and version

Pycharm 2021.3.1

OS name and version

Windows

@Hellebore Hellebore added the bug Something isn't working label Feb 22, 2022
@Hellebore
Copy link
Collaborator

Thanks for raising - have reproduced the issue and will look into a fix.

@Hellebore Hellebore added the next release This will be fixed in next release label Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working next release This will be fixed in next release
Projects
None yet
Development

No branches or pull requests

2 participants