Skip to content
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

make the import hook compatible with python3.12 #230

Merged
merged 2 commits into from
Nov 28, 2023

Conversation

aisk
Copy link
Member

@aisk aisk commented Nov 26, 2023

Also a little refactor on the old ThriftImporter, since we can using the is operator to compare to class instances, so the __eq__ overload is not needed.

fix: #229

Summary by CodeRabbit

  • New Features

    • Introduced compatibility with Python 3.4 and later for ThriftImporter functionality.
  • Refactor

    • Updated import mechanisms to align with Python 3.4+ importlib specifications.
  • Chores

    • Updated .gitignore to include the 'venv' directory, indicating a virtual environment setup.

@aisk aisk force-pushed the modern-import-hook branch from b9a67bc to 9e537ed Compare November 26, 2023 09:03
@aisk aisk requested a review from ethe November 26, 2023 09:04
@aisk aisk closed this Nov 27, 2023
@aisk aisk reopened this Nov 27, 2023
@aisk
Copy link
Member Author

aisk commented Nov 27, 2023

@coderabbitai review

Copy link

coderabbitai bot commented Nov 27, 2023

Warning

Rate Limit Exceeded

@aisk has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 9 minutes and 1 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 9e537ed and be219f0.

Walkthrough

The changes involve updating the import hook mechanism in the thriftpy2 library to be compatible with Python 3.12 by replacing the deprecated find_module method with find_spec, and adding compatibility for the module spec system introduced in Python 3.4. Additionally, a .gitignore update suggests the introduction or modification of a virtual environment.

Changes

File(s) Change Summary
.gitignore Added 'venv' directory to ignore list.
thriftpy2/hook.py Updated ThriftImporter for Python 3.4+ compatibility by using find_spec and added ThriftLoader with create_module and exec_module methods.

Assessment against linked issues

Objective Addressed Explanation
import hook does not work with Python3.12 (#229) The update from find_module to find_spec and the addition of ThriftLoader with the required methods address the compatibility issue with Python 3.12 as described in the issue.

Poem

In the code where bytes and types hop,
A rabbit tweaked the import's top.
With a find_spec in place, no more flop,
The thrifty code now runs non-stop. 🐇💻


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a7b17e0 and 9e537ed.
Files selected for processing (2)
  • .gitignore (1 hunks)
  • thriftpy2/hook.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • .gitignore
Additional comments: 1
thriftpy2/hook.py (1)
  • 14-16: The comment indicates a known issue with the load process not being compatible with the Python standard. It would be beneficial to address this issue or provide more context on how it might be resolved in the future.

Comment on lines 36 to 37
def exec_module(self, module):
...
Copy link

@coderabbitai coderabbitai bot Nov 27, 2023

Choose a reason for hiding this comment

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

The exec_module method in the ThriftLoader class is not implemented and contains only an ellipsis. This method should be properly implemented to execute the module's code within the given module's namespace.

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't need update the module, the module's content is already modified by create_module.

Copy link

Choose a reason for hiding this comment

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

@aisk Understood. If the module's content is being adequately handled by create_module, then leaving exec_module as is makes sense according to your implementation strategy. Thank you for the clarification.

thriftpy2/hook.py Outdated Show resolved Hide resolved
@ethe ethe merged commit 9a2553a into Thriftpy:master Nov 28, 2023
8 checks passed
@aisk aisk deleted the modern-import-hook branch November 28, 2023 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

import hook does not work with Python3.12
2 participants