Thriftpy / thriftpy2

Pure python approach of Apache Thrift.
MIT License
567 stars 90 forks source link

make the import hook compatible with python3.12 #230

Closed aisk closed 9 months ago

aisk commented 9 months ago

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

aisk commented 9 months ago

@coderabbitai review

coderabbitai[bot] commented 9 months ago

[!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](https://coderabbit.ai/docs/faq) for further information.
Commits Files that changed from the base of the PR and between 9e537edd148b33c87b3c8ddbaa9f68a1429b13dd and be219f01c6b7379393f0150f98cade4b12ce3777.

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](https://coderabbit.ai/integrations/coderabbit-overrides.v2.json). - 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`