-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
base: master
Are you sure you want to change the base?
Rework on #109 #111
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
There was a problem hiding this 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 ofList[str]
). - Python 2 Compatibility Removal: I've removed legacy Python 2 compatibility code, such as the
sys.version_info
checks forbasestring
andstack_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()
withdatetime.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
-
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. ↩
PR Code Suggestions ✨Explore these optional code suggestions:
|
There was a problem hiding this 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
if sys.version_info.major == 3 and sys.version_info.minor >= 12: | |
if sys.version_info >= (3, 12): |
I'm actually surprised that on the surface level the gemini code review looks rather sensible. |
PR Type
Enhancement
Description
Modernize Python code to support versions 3.9-3.12
Replace deprecated
datetime.utcnow()
with timezone-aware alternativeUpdate string formatting to use f-strings
Remove Python 2 compatibility code
Changes diagram
Changes walkthrough 📝
6 files
Convert string formatting to f-strings
Modernize super() calls
Remove Python 2 compatibility code
Simplify file opening logic
Add Python 3.12 taskName attribute support
Use modern type hints
8 files
Remove coding declaration
Remove coding declaration
Remove coding declaration
Remove empty line
Remove coding declaration
Remove coding declaration
Remove coding declaration
Remove coding declaration
3 files
Fix datetime deprecation and super() calls
Fix datetime deprecation and modernize class
Fix datetime deprecation warning
1 files
Update GitHub Actions to latest versions