Refactor: Convert string concatenation to f-strings#469
Closed
Jomaguy wants to merge 1 commit intoarthurdejong:masterfrom
Closed
Refactor: Convert string concatenation to f-strings#469Jomaguy wants to merge 1 commit intoarthurdejong:masterfrom
Jomaguy wants to merge 1 commit intoarthurdejong:masterfrom
Conversation
arthurdejong
reviewed
May 5, 2025
| r'(\s*\\\\\s*(?P<bands>[^\\]*)' + | ||
| r'(\s*\\\\\s*(?P<notes>[^\\]*)' + | ||
| r')?)?)?)?)?') | ||
| "^\|\s*(?P<mcc>[0-9]+)\s*\\\\\s*(?P<mnc>[0-9]+)"+)'}(\s*\\\\\s*(?P<brand>[^\\]*)"*)'}(\s*\\\\\s*(?P<operator>[^\\]*)"*)'}(\s*\\\\\s*(?P<status>[^\\]*)"*)'}(\s*\\\\\s*(?P<bands>[^\\]*)"*)'}(\s*\\\\\s*(?P<notes>[^\\]*)"*)'})?)?)?)?)?") |
Owner
There was a problem hiding this comment.
I don't think this makes the code more readable. The original regex already has some readability issues but at least the splitting over multiple lines tries to make it a little better readable.
Also flake8 gives some errors.
Owner
|
Closing this for now. Feel free to re-open when flake8 issues have been addressed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Convert Python String Concatenation to F-strings
Overview
This PR refactors string concatenation patterns in the codebase to use Python f-strings introduced in Python 3.6. The refactoring was performed automatically using a custom codemod tool built with Codegen.
The Pattern Being Refactored
The codemod identifies and converts several string concatenation patterns:
String + variable concatenation:
Variable + string concatenation:
String + string concatenation:
Benefits of the Refactoring
How the Codemod Works
The codemod uses regular expressions to identify string concatenation patterns in Python files and transforms them into equivalent f-string expressions:
It searches for three main patterns:
For each match, it transforms the code while preserving:
The transformation carefully avoids:
Changes Summary
The changes maintain the exact same functionality while making the code more readable and maintainable. The PR touched 3 files in the
update/directory:update/cn_loc.py: Converted string concatenation patterns in thegroup_datafunctionupdate/iban.py: Converted string concatenation in the IBAN prefix checking logicupdate/imsi.py: Converted string concatenation in regular expression patternsAll changes have been verified to maintain the original behavior.
Testing
The transformed code was verified by:
No functional changes were introduced by this refactoring.