json-logging-python icon indicating copy to clipboard operation
json-logging-python copied to clipboard

Rework on #109

Open mavwolverine opened this issue 7 months ago • 11 comments

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()"]

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.
  • mavwolverine avatar Jul 12 '25 21:07 mavwolverine

    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")
    

    qodo-code-review[bot] avatar Jul 12 '25 21:07 qodo-code-review[bot]

    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 <!-- /improve --apply_suggestion=0 -->
    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 <!-- /improve --apply_suggestion=1 -->
    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 <!-- /improve_multi --more_suggestions=true -->

    qodo-code-review[bot] avatar Jul 12 '25 21:07 qodo-code-review[bot]

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

    dwt avatar Jul 13 '25 17:07 dwt

    @mavwolverine Do these suggestions by the AI make sense to you?

    dwt avatar Jul 19 '25 15:07 dwt

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

    Yes, I was surprised too. How did you add it? Thanks

    mavwolverine avatar Jul 20 '25 14:07 mavwolverine

    @mavwolverine Do these suggestions by the AI make sense to you?

    Yes, the suggestions do make sense, and it has covered areas I did not touch just based on the commit message. That is great!

    One thing I am unsure on is the timezone change https://github.com/bobbui/json-logging-python/pull/111#discussion_r2202918092

    mavwolverine avatar Jul 20 '25 14:07 mavwolverine

    It is suggesting "The most direct fix would be to remove .replace(tzinfo=None) in formatters.py", but it seems to be something added recently. So not sure on that.

    mavwolverine avatar Jul 20 '25 14:07 mavwolverine

    Updated PR for other 2 suggestions

    mavwolverine avatar Jul 20 '25 14:07 mavwolverine

    @mavwolverine actually I didn't. I am pretty sure @bobbui did that. (Thanks for that @bobbui!).

    dwt avatar Jul 21 '25 12:07 dwt

    It is suggesting "The most direct fix would be to remove .replace(tzinfo=None) in formatters.py", but it seems to be something added recently. So not sure on that.

    Well, that was introduced to work around python 3.12 deprecations. Looking at the other function this calls iso_time_format that already appends a Z to the timestamp to mark it as ZULU/UTC, so the suggestion of gemini seems sensible for me?

    dwt avatar Jul 26 '25 16:07 dwt

    Friendly ping @mavwolverine - did you notice the feedback I gave you?

    dwt avatar Aug 19 '25 08:08 dwt