Refactor: Convert string concatenation to f-strings #469
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_data
functionupdate/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.