To modernize the codebase and improve readability, this issue aims to refactor all instances of string formatting to use f-strings. F-strings (formatted string literals) are more readable and concise than the older .format() method or the % operator. This update will make the code more consistent with modern Python practices and enhance maintainability.
Objectives:
Identify all instances of string formatting in the codebase.
Refactor these instances to use f-strings.
Ensure all unit tests pass after the refactor.
Tasks:
Identify String Formatting Instances:
Search the codebase for occurrences of .format() and % for string formatting.
Refactor to f-strings:
Replace .format() and % with f-strings.
Ensure the new f-strings maintain the same functionality and output.
Verify Changes:
Run all existing unit tests to ensure they pass.
Manually test key functionality if needed to verify correctness.
Implementation Plan:
Search and Replace:
Use tools like grep or IDE search functionality to find string formatting instances.
Refactor each instance to use f-strings.
Example Refactors:
Current Code:
repo_folder = repo_id.replace('/', '---')
print("Error getting info for repo {}: {}".format(repo_id, e))
Improved Code:
repo_folder = repo_id.replace('/', '---')
print(f"Error getting info for repo {repo_id}: {e}")
Verify with Unit Tests:
Run pytest to execute all unit tests.
Confirm that all tests pass without any errors.
Steps to Reproduce:
Clone the repository:
git clone <repository-url>
Navigate to the directory containing the code to be refactored.
Search for string formatting instances:
grep -r -E "\.format\(|%" <directory>
Refactor each instance to use f-strings.
Run the tests to verify the changes:
pytest
Expected Behavior:
The codebase should use f-strings for all string formatting.
The code should be more readable and maintainable.
All unit tests should pass, confirming that functionality remains unchanged.
Current Behavior:
The codebase currently uses a mix of .format(), %, and potentially other methods for string formatting.
Additional Information:
Progress Log:
2024-07-27: Initial setup of the issue and identification of string formatting instances to be refactored.
Description:
To modernize the codebase and improve readability, this issue aims to refactor all instances of string formatting to use f-strings. F-strings (formatted string literals) are more readable and concise than the older
.format()
method or the%
operator. This update will make the code more consistent with modern Python practices and enhance maintainability.Objectives:
Tasks:
Identify String Formatting Instances:
.format()
and%
for string formatting.Refactor to f-strings:
.format()
and%
with f-strings.Verify Changes:
Implementation Plan:
Search and Replace:
grep
or IDE search functionality to find string formatting instances.Example Refactors:
Current Code:
Improved Code:
Verify with Unit Tests:
pytest
to execute all unit tests.Steps to Reproduce:
Expected Behavior:
Current Behavior:
.format()
,%
, and potentially other methods for string formatting.Additional Information:
Progress Log: