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 it better! #50

Merged
merged 5 commits into from
Jan 17, 2025
Merged

Make it better! #50

merged 5 commits into from
Jan 17, 2025

Conversation

majiidd
Copy link
Owner

@majiidd majiidd commented Jan 17, 2025

Summary by CodeRabbit

Release Notes for Version 5.2.0

  • New Features

    • Enhanced character conversion functions using regular expressions.
    • Improved date handling in Jalali date and time classes.
  • Improvements

    • Updated copyright year to 2025.
    • Added more comprehensive docstrings for date and time properties.
  • Testing

    • Expanded test coverage for character conversion and date handling.
    • Added new test cases for edge cases and date conversions.
  • Maintenance

    • Updated package version to 5.2.0.

Copy link

coderabbitai bot commented Jan 17, 2025

Walkthrough

This pull request introduces version 5.2.0 of the persiantools library, featuring several improvements across different components. The changes include updates to character conversion methods using regular expressions, enhancements to the JalaliDate and JalaliDateTime classes with improved code structure and documentation, and expanded test coverage. The version number, changelog, and license have been correspondingly updated to reflect these modifications.

Changes

File Change Summary
CHANGELOG.md Added version 5.2.0 entry dated 2025-01-17, enhanced character conversion functions, improved date handling, and added new test cases.
LICENSE Updated copyright year from 2024 to 2025.
persiantools/__init__.py Updated package version from 5.1.1 to 5.2.0.
persiantools/characters.py Replaced replace function with regex-based character mapping and added new regex patterns.
persiantools/jdatetime.py Refactored date handling, improved immutability, and added docstrings to properties and methods.
tests/test_characters.py Added error handling tests for None inputs in character conversion methods.
tests/test_jalalidate.py Expanded test cases for date conversions and leap years, including new and modified assertions.
tests/test_digits.py Added test case for handling out-of-range floating-point input in to_word method.

Possibly related PRs

Poem

🐰 Hop, hop, through code so bright,
Persiantools leaps to new height!
Regex dancing, dates so clear,
Version 5.2.0 brings cheer!
Rabbit's code, a joyful sight! 🎉

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@codecov-commenter
Copy link

codecov-commenter commented Jan 17, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.44%. Comparing base (0c0e801) to head (33bfdc6).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #50      +/-   ##
==========================================
+ Coverage   92.96%   93.44%   +0.47%     
==========================================
  Files           5        5              
  Lines         938      930       -8     
==========================================
- Hits          872      869       -3     
+ Misses         66       61       -5     

☔ 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

🧹 Nitpick comments (2)
persiantools/characters.py (1)

17-18: LGTM! Consider following Python's naming convention for constants.

The regex pattern compilation is a good optimization. However, consider using uppercase for the entire constant names (e.g., _AR_TO_FA_PATTERN) since these are module-level constants.

-AR_TO_FA_PATTERN = re.compile("|".join(map(re.escape, CHARACTER_MAP_AR_TO_FA.keys())))
-FA_TO_AR_PATTERN = re.compile("|".join(map(re.escape, CHARACTER_MAP_FA_TO_AR.keys())))
+_AR_TO_FA_PATTERN = re.compile("|".join(map(re.escape, CHARACTER_MAP_AR_TO_FA.keys())))
+_FA_TO_AR_PATTERN = re.compile("|".join(map(re.escape, CHARACTER_MAP_FA_TO_AR.keys())))
tests/test_characters.py (1)

35-37: LGTM! Consider adding a comment explaining the test case.

The test case is valuable as it covers multiple character conversions. Consider adding a comment explaining what specific aspects of the conversion this test case validates.

+        # Test multiple character conversions: Arabic Ya (ي), Persian Ya (ی), Arabic Kaf (ك), and diacritics
         input_string = "يياكشيسِ"
         expected_output = "ییاکشیس"
         self.assertEqual(characters.ar_to_fa(input_string), expected_output)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0c0e801 and e31d139.

📒 Files selected for processing (7)
  • CHANGELOG.md (1 hunks)
  • LICENSE (1 hunks)
  • persiantools/__init__.py (1 hunks)
  • persiantools/characters.py (4 hunks)
  • persiantools/jdatetime.py (9 hunks)
  • tests/test_characters.py (2 hunks)
  • tests/test_jalalidate.py (13 hunks)
✅ Files skipped from review due to trivial changes (3)
  • LICENSE
  • persiantools/init.py
  • CHANGELOG.md
🔇 Additional comments (13)
persiantools/characters.py (2)

41-41: Great performance optimization!

The new regex-based implementation is more efficient as it handles all replacements in a single pass through the string, compared to multiple string replacements in the previous version.


64-64: LGTM! Consistent implementation with ar_to_fa.

The implementation maintains consistency with the ar_to_fa function, sharing the same efficient regex-based approach.

tests/test_characters.py (2)

27-28: LGTM! Good edge case coverage.

Adding explicit None input testing strengthens the test suite's coverage of edge cases.


59-60: LGTM! Consistent error handling test coverage.

Good addition of None input testing for fa_to_ar, maintaining consistency with ar_to_fa's error handling tests.

tests/test_jalalidate.py (4)

Line range hint 15-71: Well-structured and comprehensive test cases!

The test cases for Jalali to Gregorian conversion are thorough and cover:

  • Wide date range (1100-1505)
  • Edge cases around year transitions
  • Leap year scenarios

Line range hint 93-118: Excellent bidirectional conversion coverage!

The test cases for Gregorian to Jalali conversion are well-designed with:

  • Historical dates (1827-2119)
  • Matching pairs with the Jalali to Gregorian tests
  • Edge cases around calendar transitions

Line range hint 291-319: Good coverage of leap year edge cases!

The test cases effectively validate non-leap years, particularly focusing on:

  • Years that are exceptions to the 33-year leap year rule
  • Sequential years to verify boundary conditions

431-431: Good test coverage for week-related calculations!

The test cases properly validate:

  • Week of year calculation
  • Weekday determination
  • ISO weekday conversion

Also applies to: 444-445, 450-450

persiantools/jdatetime.py (5)

135-149: Excellent optimization using frozenset!

The changes improve the code by:

  1. Using frozenset for faster membership testing in is_leap()
  2. Making the collection immutable to prevent accidental modifications
  3. Adding an explicit MIN_NON_LEAP_CORRECTION constant for better readability

Line range hint 204-217: Clean and concise initialization logic!

The initialization has been improved through:

  • Better use of tuple unpacking
  • Clearer flow of logic
  • More maintainable code structure

222-257: Well-documented properties!

The added docstrings:

  • Follow proper documentation format
  • Clearly describe return values
  • Improve code maintainability

Line range hint 342-347: Improved readability of leap year validation!

The condition check is now:

  • More readable with proper parentheses
  • Maintains the same logic with better clarity

1032-1077: Excellent property documentation in JalaliDateTime!

The added docstrings:

  • Follow proper documentation format
  • Clearly describe return values
  • Improve code maintainability

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

🧹 Nitpick comments (2)
tests/test_digits.py (1)

88-90: LGTM! Consider adding a descriptive message.

Good addition of an edge case test for floating-point number handling. The test case improves coverage and is well-placed with other exception tests.

Consider adding a descriptive message to the assertion to clarify the specific scenario being tested:

 with pytest.raises(digits.OutOfRangeException):
-    digits.to_word(0.123456789012345)
+    digits.to_word(0.123456789012345, msg="Should raise OutOfRangeException for floating-point numbers with too many decimal places")
CHANGELOG.md (1)

4-9: Consider adding more specific details to the changelog entries.

While the changelog entries follow the correct format, they could be more specific about the actual changes made. This helps users and developers better understand the impact of the update.

Consider expanding the entries like this:

 ## [5.2.0](https://github.com/majiidd/persiantools/compare/5.1.1...5.2.0) - 2025-01-17

-Enhanced character conversion functions using regular expressions.
-Improved date handling in Jalali date and time classes.
-Added new test cases for edge cases and date conversions.
+- Enhanced character conversion functions using regular expressions for better performance and maintainability.
+- Improved date handling in Jalali date and time classes with better error handling and validation.
+- Added new test cases for edge cases in number conversion and date handling, improving overall test coverage.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e31d139 and 33bfdc6.

📒 Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • tests/test_digits.py (1 hunks)
  • tests/test_jalalidate.py (15 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_jalalidate.py
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: windows-latest / 3.13

@majiidd majiidd merged commit e3a85b8 into master Jan 17, 2025
23 checks passed
@majiidd majiidd deleted the make-it-better branch January 17, 2025 20:19
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.

2 participants