-
-
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_infochecks forbasestringandstack_info, and the# coding=utf-8headers 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
taskNameattribute 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.pywhere a change to make_epochtimezone-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.pyscript 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.
|
|
||
|
|
||
| _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.
setup.py
Outdated
| 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()
tests/helpers/constants.py
Outdated
| } | ||
| ] | ||
|
|
||
| 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. |
|
@mavwolverine Do these suggestions by the AI make sense to you? |
Yes, I was surprised too. How did you add it? Thanks |
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 #111 (comment) |
|
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. |
|
Updated PR for other 2 suggestions |
|
@mavwolverine actually I didn't. I am pretty sure @bobbui did that. (Thanks for that @bobbui!). |
Well, that was introduced to work around python 3.12 deprecations. Looking at the other function this calls |
|
Friendly ping @mavwolverine - did you notice the feedback I gave you? |
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-stringsModernize super() callsRemove Python 2 compatibility codeSimplify file opening logicAdd Python 3.12 taskName attribute supportUse modern type hints8 files
Remove coding declarationRemove coding declarationRemove coding declarationRemove empty lineRemove coding declarationRemove coding declarationRemove coding declarationRemove coding declaration3 files
Fix datetime deprecation and super() callsFix datetime deprecation and modernize classFix datetime deprecation warning1 files
Update GitHub Actions to latest versions