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

Find all converter subclasses / descendants #110

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

rlskoeser
Copy link
Member

@rlskoeser rlskoeser commented Feb 7, 2025

Revises converter subclass logic to find nested / descendant classes.

This resolves an issue I discovered when I tried to subclass the Hebrew converter to add a Seleucid calendar converter and the subclass wasn't being found.

Summary by CodeRabbit

  • Refactor
    • Enhanced the mechanism for gathering converter classes by switching from a list to a set and enabling recursive inclusion of all nested converter types while excluding specific ones.
  • Tests
    • Introduced a new test to verify that the updated converter collection correctly identifies subclasses, ensuring expected converters are included while excluding specific ones.

Copy link
Contributor

coderabbitai bot commented Feb 7, 2025

Warning

Rate limit exceeded

@rlskoeser has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 28 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

Reviewing files that changed from the base of the PR and between 0deb9ad and 6c8c639.

📒 Files selected for processing (1)
  • src/undate/converters/base.py (1 hunks)

Walkthrough

The pull request updates the BaseDateConverter class by changing the subclasses method's return type from a list to a set. The method's implementation is enhanced to recursively gather all nested subclasses while explicitly excluding BaseCalendarConverter. Additionally, a new test method is introduced to ensure that the correct converter subclasses are included and that BaseCalendarConverter is omitted from the results.

Changes

File Change Summary
src/…/base.py Modified BaseDateConverter.subclasses: changed return type from list to set; updated logic to recursively aggregate all nested subclasses while excluding BaseCalendarConverter.
tests/…/test_base.py Added test_subclasses within TestBaseDateConverter to verify that all expected subclasses are returned and that BaseCalendarConverter is excluded.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Test/Caller
    participant BDC as BaseDateConverter
    participant Sub as Direct Subclass

    Caller->>BDC: call subclasses() 
    BDC->>BDC: Retrieve __subclasses__()
    loop For each direct subclass
        BDC->>Sub: call subclasses()
        Sub-->>BDC: Return nested subclasses
    end
    BDC->>BDC: Exclude BaseCalendarConverter
    BDC-->>Caller: Return aggregated subclass set
Loading

Poem

I'm a rabbit who hops with glee,
Seeing subclass magic in our code tree.
From lists to sets, the changes are neat,
Recursive calls make our converters complete.
BaseCalendarConverter hops out of sight,
Celebrating new flow by moonlit byte!


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.

Copy link
Contributor

@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 (1)
src/undate/converters/base.py (1)

117-121: Clarify the docstring to reflect the returned set.

The docstring mentions "List of available converters," but the method now returns a set. Updating the docstring for accuracy would help maintain clarity.

Here's a suggested fix:

-        List of available converters classes. Includes calendar convert
+        Set of available converter classes. Includes calendar converter
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a33e43b and f6c4382.

📒 Files selected for processing (2)
  • src/undate/converters/base.py (2 hunks)
  • tests/test_converters/test_base.py (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: python-unit (3.13)
  • GitHub Check: python-unit (3.12)
  • GitHub Check: python-unit (3.11)
  • GitHub Check: python-unit (3.10)
  • GitHub Check: python-unit (3.9)
🔇 Additional comments (4)
src/undate/converters/base.py (2)

126-132: Validate recursion safety.

This recursive approach effectively gathers nested subclasses. Should a rare case of cyclic inheritance arise (which Python disallows by default), it could cause issues, but given standard class inheritance rules, this is safe and correct.


133-134: Excluding BaseCalendarConverter seems appropriate.

Removing the base calendar converter from the final set aligns with the documented intent to exclude non-functional base implementations.

tests/test_converters/test_base.py (2)

5-9: Selective imports are clean and concise.

Listing only the required calendar converters is a good practice that promotes clarity in tests.


37-48: Thorough subclass coverage test.

Defining a nested subclass and verifying its inclusion ensures proper coverage of the recursive subclass logic. This test appropriately confirms that the base calendar converter is excluded while derived converters are included.

Copy link
Contributor

@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 (1)
src/undate/converters/base.py (1)

127-136: Implementation looks good but remove the debug print.

The recursive implementation correctly finds all nested subclasses while excluding BaseCalendarConverter. However, there's a commented out debug print statement that should be removed.

-            # print(f"class subclasses: {subc.name} {subc.subclasses()}")
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f6c4382 and 0deb9ad.

📒 Files selected for processing (1)
  • src/undate/converters/base.py (1 hunks)
🔇 Additional comments (3)
src/undate/converters/base.py (3)

117-117: LGTM! Good choice using a set return type.

The change from list to set is appropriate since order doesn't matter for converter subclasses and sets prevent duplicates while enabling cleaner set operations.


119-121: LGTM! Documentation accurately reflects the changes.

The docstring clearly explains that descendant subclasses are included while BaseCalendarConverter is excluded.


127-133: Verify that nested calendar converters are discovered correctly.

Let's confirm that the recursive implementation correctly discovers nested calendar converters, particularly for the Hebrew calendar use case mentioned in the PR description.

✅ Verification successful

🏁 Script executed:

#!/bin/bash
# Description: Check if nested calendar converters are discovered correctly

# Search for Hebrew calendar converter and its subclasses
ast-grep --pattern $'class HebrewDateConverter {
  $$$
}'

# Search for any classes that extend HebrewDateConverter
ast-grep --pattern $'class $_ extends HebrewDateConverter {
  $$$
}'

Length of output: 128


I'll generate a new shell script to search for Hebrew calendar converters using regex patterns suitable for Python syntax. This will help us verify whether HebrewDateConverter and its subclasses are defined in the codebase.


🏁 Script executed:

#!/bin/bash
echo "Searching for the declaration of HebrewDateConverter:"
rg "class\s+HebrewDateConverter\s*\(" -n

echo ""
echo "Searching for any classes inheriting from HebrewDateConverter:"
rg "class\s+[A-Za-z0-9_]+\s*\(.*HebrewDateConverter.*\)\s*:" -n

Length of output: 476


Nested Converter Discovery Works as Intended

The recursive subclass collection in the base converter (using subclasses() and set unions) is correctly implemented. Our searches confirm that HebrewDateConverter is defined, and although no additional subclasses were found for it in the Hebrew calendar module, the recursive logic will discover any nested converters if they are added.

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.

1 participant