Skip to content

Rework on #109 #111

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

mavwolverine
Copy link

@mavwolverine mavwolverine commented Jul 12, 2025

PR Type

Enhancement


Description

  • Modernize Python code to support versions 3.9-3.12

  • Replace deprecated datetime.utcnow() with timezone-aware alternative

  • Update string formatting to use f-strings

  • Remove Python 2 compatibility code


Changes diagram

flowchart LR
  A["Python 2/3 compatibility code"] --> B["Python 3.9+ only code"]
  C["datetime.utcnow()"] --> D["datetime.now(timezone.utc)"]
  E["String format()"] --> F["f-strings"]
  G["super(Class, self)"] --> H["super()"]
Loading

Changes walkthrough 📝

Relevant files
Enhancement
6 files
hello.py
Convert string formatting to f-strings                                     
+2/-2     
custom_log_format_request.py
Modernize super() calls                                                                   
+3/-3     
formatters.py
Remove Python 2 compatibility code                                             
+6/-9     
setup.py
Simplify file opening logic                                                           
+1/-1     
constants.py
Add Python 3.12 taskName attribute support                             
+9/-2     
handler.py
Use modern type hints                                                                       
+1/-1     
Formatting
8 files
__init__.py
Remove coding declaration                                                               
+0/-1     
__init__.py
Remove coding declaration                                                               
+0/-1     
__init__.py
Remove coding declaration                                                               
+0/-1     
__init__.py
Remove empty line                                                                               
+0/-1     
__init__.py
Remove coding declaration                                                               
+0/-1     
__init__.py
Remove coding declaration                                                               
+0/-1     
__init__.py
Remove coding declaration                                                               
+0/-1     
framework_base.py
Remove coding declaration                                                               
+0/-1     
Bug fix
3 files
dto.py
Fix datetime deprecation and super() calls                             
+3/-3     
util.py
Fix datetime deprecation and modernize class                         
+3/-4     
benmark_micro.py
Fix datetime deprecation warning                                                 
+2/-3     
Dependencies
1 files
code_quality.yml
Update GitHub Actions to latest versions                                 
+6/-6     

Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Logic Error

    The Python 2/3 compatibility code has been incorrectly modified. The variable io_open is now assigned but io.open is no longer used, which will cause a NameError when Python version is not 3.

    io_open = open('README.rst', encoding="utf8")
    long_description = io_open.read()
    Compatibility Issue

    The version check for adding 'taskName' attribute only considers Python 3.12+, but the PR description mentions support for Python 3.9-3.12. This may cause inconsistent behavior across supported versions.

    if sys.version_info.major == 3 and sys.version_info.minor >= 12:
        _msg_attrs.append("taskName")

    Copy link

    @gemini-code-assist gemini-code-assist bot left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Summary of Changes

    Hello @mavwolverine, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

    This pull request represents a significant modernization effort, primarily focused on updating the codebase to align with contemporary Python 3 best practices and remove outdated Python 2 compatibility constructs. The changes streamline syntax, enhance datetime handling for improved accuracy, and ensure forward compatibility with the latest Python versions.

    Highlights

    • Python Modernization: I've updated the codebase to leverage modern Python 3 features, including f-strings for string formatting, implicit super() calls, and contemporary type hinting syntax (e.g., list[str] instead of List[str]).
    • Python 2 Compatibility Removal: I've removed legacy Python 2 compatibility code, such as the sys.version_info checks for basestring and stack_info, and the # coding=utf-8 headers which are no longer necessary in Python 3.
    • Timezone-Aware Datetime Handling: I've updated datetime operations to be timezone-aware, replacing deprecated datetime.utcnow() with datetime.now(timezone.utc) and ensuring epoch calculations are also timezone-aware.
    • Python 3.12 Compatibility: I've added conditional logic to include the taskName attribute in expected log record attributes for Python 3.12 and newer, ensuring compatibility with recent Python versions.
    Using Gemini Code Assist

    The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

    Invoking Gemini

    You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

    Feature Command Description
    Code Review /gemini review Performs a code review for the current pull request in its current state.
    Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
    Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
    Help /gemini help Displays a list of available commands.

    Customization

    To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

    Limitations & Feedback

    Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

    You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

    Footnotes

    1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

    Copy link

    qodo-merge-pro bot commented Jul 12, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Fix timezone-aware epoch calculation

    The epoch calculation should use UTC timezone consistently. The current
    implementation may cause issues with timezone-aware datetime operations when
    comparing with other datetime objects.

    json_logging/util.py [73]

    +_epoch = datetime(1970, 1, 1, tzinfo=timezone.utc)
     
    -
    • Apply / Chat
    Suggestion importance[1-10]: 3

    __

    Why: The suggestion correctly identifies a positive change in the PR but offers no new improvement, as the improved_code is identical to the code already present in the PR.

    Low
    Verify timezone consistency across codebase

    Using datetime.now(timezone.utc) is correct for timezone-aware UTC time.
    However, ensure this change is consistent with the rest of the codebase's
    datetime handling patterns.

    tests-performance/benmark_micro.py [5]

    +utcnow = datetime.now(timezone.utc)
     
    -
    • Apply / Chat
    Suggestion importance[1-10]: 3

    __

    Why: This suggestion correctly affirms the PR's change but only advises verifying consistency, which is a general good practice rather than a specific, actionable code improvement.

    Low
    • Update

    Copy link

    @gemini-code-assist gemini-code-assist bot left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Code Review

    This pull request does a great job of modernizing the codebase by removing Python 2 compatibility code, updating to f-strings, and using timezone-aware datetimes. The changes are well-aligned with the goal of supporting Python 3.9+.

    I've found a few areas for improvement:

    • A critical issue in util.py where a change to make _epoch timezone-aware will cause runtime errors in other parts of the code that have not been updated to pass timezone-aware datetimes.
    • An opportunity to simplify the setup.py script by removing obsolete Python 2/3 compatibility logic.
    • A minor style improvement in a test helper for version checking.

    Please review my comments for details.

    @@ -71,7 +70,7 @@ def validate_subclass(subclass, superclass):
    return True


    _epoch = datetime(1970, 1, 1)
    _epoch = datetime(1970, 1, 1, tzinfo=timezone.utc)

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    critical

    Making _epoch a timezone-aware datetime object is a good step towards modernizing the codebase. However, this change will cause a TypeError at runtime. The function epoch_nano_second will now fail when called with a timezone-naive datetime object, as it's not possible to subtract a naive from an aware datetime.

    For example, json_logging.formatters.BaseJSONFormatter._format_log_object calls it with a naive datetime:

    # json_logging/formatters.py:61
    utcnow = datetime.now(timezone.utc).replace(tzinfo=None)
    ...
    # json_logging/formatters.py:65
    "written_ts": json_logging.util.epoch_nano_second(utcnow),

    To fix this, you need to ensure that all callers of epoch_nano_second pass a timezone-aware datetime object. The most direct fix would be to remove .replace(tzinfo=None) in formatters.py, but that change is outside the scope of this diff. Please ensure all call sites are updated to prevent runtime failures.

    Comment on lines 7 to 11
    if version_info_major == 3:
    long_description = open('README.rst', encoding="utf8").read()
    else:
    io_open = io.open('README.rst', encoding="utf8")
    io_open = open('README.rst', encoding="utf8")
    long_description = io_open.read()

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    medium

    Since this pull request drops support for Python 2 and targets Python 3.9+, this entire if/else block for version compatibility is no longer necessary. The else branch is now dead code.

    You can simplify this logic to directly read the file. Using a with statement is also recommended for handling files as it ensures they are closed properly even if errors occur.

    with open('README.rst', encoding="utf8") as f:
        long_description = f.read()

    }
    ]

    if sys.version_info.major == 3 and sys.version_info.minor >= 12:

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    medium

    The version check can be made more concise and idiomatic by comparing the sys.version_info tuple directly. This improves readability and is the recommended way to perform version checks.

    Suggested change
    if sys.version_info.major == 3 and sys.version_info.minor >= 12:
    if sys.version_info >= (3, 12):

    @dwt
    Copy link

    dwt commented Jul 13, 2025

    I'm actually surprised that on the surface level the gemini code review looks rather sensible.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants