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

Add missing functools.wraps decorator to deprecated decorator and handle dataclass properly #699

Merged
merged 18 commits into from
Jul 23, 2024

Conversation

DanielYang59
Copy link
Contributor

@DanielYang59 DanielYang59 commented Jul 21, 2024

Summary

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Improved handling of deprecated functions and classes for better clarity and usability of warnings, especially for dataclasses.
    • Enhanced type annotation specificity in the JSON handling component, leading to clearer code.
  • Bug Fixes

    • Ensured proper metadata preservation for deprecated functions and classes to aid in debugging and documentation clarity.
  • Documentation

    • Updated docstrings to follow Google-style formatting for improved readability and structure.
    • Clarified purposes of deprecated functions and classes through enhanced documentation.

Copy link

coderabbitai bot commented Jul 21, 2024

Warning

Rate limit exceeded

@DanielYang59 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 22 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 as a PR comment. 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 d6dd735 and 4337bb1.

Walkthrough

The recent changes enhance the handling of deprecated functions and classes throughout the codebase. They improve metadata preservation through decorators, adopt more precise type annotations, and refine documentation practices. These modifications aim to modernize the code, ensuring clarity and maintainability while preserving existing functionality.

Changes

Files Change Summary
src/monty/dev.py Improved deprecated function and class decorators with metadata preservation and refined handling for dataclasses.
src/monty/json.py Updated type annotations for dictionaries, revised docstrings to align with Google-style format, and added type hints to class methods and attributes.
tests/test_dev.py Enhanced documentation for deprecated functions and classes, including clearer docstrings and assertions for metadata preservation.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DeprecatedFunction
    participant Documentation

    User->>DeprecatedFunction: Call deprecated function
    DeprecatedFunction->>Documentation: Log deprecation warning
    Documentation-->>User: Provide function metadata
Loading

🐇 In the garden, changes bloom bright,
To make our code a sheer delight.
With docs so clear, and types defined,
We hop along, with peace of mind!
So celebrate, let’s dance and play,
For better code is here to stay! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@DanielYang59 DanielYang59 marked this pull request as ready for review July 21, 2024 03:37
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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between feb6e83 and eb522ca.

Files selected for processing (3)
  • src/monty/dev.py (3 hunks)
  • src/monty/json.py (7 hunks)
  • tests/test_dev.py (3 hunks)
Additional comments not posted (11)
tests/test_dev.py (4)

22-22: Good addition of docstring.

The docstring improves the documentation of the func_old function.


32-34: Good addition of metadata preservation checks.

The assertions ensure that the function's name and docstring are preserved.


120-120: Good update to class docstring.

The updated docstring provides clearer context for TestClassOld.


125-136: Good addition of docstring and metadata preservation checks.

The docstring improves the documentation of the method_b function. The assertions ensure that the class's docstring, attribute, and module name are preserved.

src/monty/dev.py (3)

125-125: Good use of functools.wraps to preserve metadata.

The addition of functools.wraps ensures that the metadata of the original function is preserved.


134-140: Good refinement of dataclass initialization logic.

The refined logic ensures that the warning message is issued appropriately when a dataclass is instantiated.


146-150: Good handling of __post_init__ and __init__ methods for dataclasses.

The change ensures that the appropriate method is modified for dataclasses, improving the usability and clarity of the deprecation warnings.

src/monty/json.py (4)

177-177: Good update to type hint for dictionary variable.

The updated type hint enhances type specificity, making the code clearer and more consistent with modern Python type hinting practices.


240-245: Good revision of docstring formatting.

The revised docstring formatting improves the readability and structure of the documentation.


554-555: Good addition of type hints to constructor parameters.

The added type hints improve type safety and clarity.


558-558: Good update to type hint for _name_object_map variable.

The updated type hint enhances type specificity, making the code clearer and more consistent with modern Python type hinting practices.

@DanielYang59 DanielYang59 changed the title Add missing functools.wraps decorator to deprecated decorator Add missing functools.wraps decorator to deprecated decorator and handle dataclass properly Jul 21, 2024
Copy link

codecov bot commented Jul 21, 2024

Codecov Report

Attention: Patch coverage is 72.00000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 80.76%. Comparing base (feb6e83) to head (1810f46).

Files Patch % Lines
src/monty/dev.py 55.55% 2 Missing and 2 partials ⚠️
src/monty/json.py 81.25% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #699      +/-   ##
==========================================
- Coverage   80.93%   80.76%   -0.17%     
==========================================
  Files          27       27              
  Lines        1563     1570       +7     
  Branches      353      357       +4     
==========================================
+ Hits         1265     1268       +3     
- Misses        234      236       +2     
- Partials       64       66       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between eb522ca and 1810f46.

Files selected for processing (1)
  • tests/test_dev.py (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/test_dev.py

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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1810f46 and 478a242.

Files selected for processing (1)
  • tests/test_dev.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/test_dev.py

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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 478a242 and 3f9fa0d.

Files selected for processing (1)
  • src/monty/json.py (7 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/monty/json.py

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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3f9fa0d and f68d9e9.

Files selected for processing (1)
  • src/monty/dev.py (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/monty/dev.py

This reverts commit f68d9e9.
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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f68d9e9 and 3e301c3.

Files selected for processing (1)
  • src/monty/dev.py (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/monty/dev.py

@DanielYang59
Copy link
Contributor Author

DanielYang59 commented Jul 22, 2024

@shyuep Can you please review this? Thanks.

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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3e301c3 and c1d6c9d.

Files selected for processing (1)
  • tests/test_dev.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/test_dev.py

try:
import dataclasses
except ImportError:
dataclasses = None # type: ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's safe to remove guard for dataclasses now.

Added in version 3.7.

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.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c1d6c9d and d6dd735.

Files selected for processing (1)
  • src/monty/json.py (8 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/monty/json.py

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.

3 participants