zimm0140 / AI-Playground

AI PC starter app for doing AI image creation, image stylizing, and chatbot on a PC powered by an Intel® Arc™ GPU.
MIT License
0 stars 0 forks source link

Refactor Codebase to Use f-strings for String Formatting #2

Open SZim92 opened 2 months ago

SZim92 commented 2 months ago

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:

  1. Identify all instances of string formatting in the codebase.
  2. Refactor these instances to use f-strings.
  3. Ensure all unit tests pass after the refactor.

Tasks:

  1. Identify String Formatting Instances:

    • Search the codebase for occurrences of .format() and % for string formatting.
  2. Refactor to f-strings:

    • Replace .format() and % with f-strings.
    • Ensure the new f-strings maintain the same functionality and output.
  3. Verify Changes:

    • Run all existing unit tests to ensure they pass.
    • Manually test key functionality if needed to verify correctness.

Implementation Plan:

  1. Search and Replace:

    • Use tools like grep or IDE search functionality to find string formatting instances.
    • Refactor each instance to use f-strings.
  2. 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}")
  3. Verify with Unit Tests:

    • Run pytest to execute all unit tests.
    • Confirm that all tests pass without any errors.

Steps to Reproduce:

  1. Clone the repository:
    git clone <repository-url>
  2. Navigate to the directory containing the code to be refactored.
  3. Search for string formatting instances:
    grep -r -E "\.format\(|%" <directory>
  4. Refactor each instance to use f-strings.
  5. Run the tests to verify the changes:
    pytest

Expected Behavior:

Current Behavior:

Additional Information:

Progress Log: