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

Improve RuleGroup typing #16

Open
trag1c opened this issue Aug 14, 2023 · 0 comments
Open

Improve RuleGroup typing #16

trag1c opened this issue Aug 14, 2023 · 0 comments
Labels
help wanted Contributions especially welcome improvement Code/documentation/DX improvements

Comments

@trag1c
Copy link
Owner

trag1c commented Aug 14, 2023

RuleGroups currently cannot be parametrized and so all rules it contains are marked as Rule[Any]:

class Rule:
    ...
    def __or__(self, other: object) -> RuleGroup:
        if isinstance(other, Rule):
            return RuleGroup((self, other))
        if isinstance(other, RuleGroup):
            return RuleGroup((self, *other.rules))
        return NotImplemented


@dataclass(frozen=True)
class RuleGroup:
    rules: tuple[Rule[Any], ...]

    def __iter__(self) -> Iterator[Rule[Any]]:
        ...

    def __or__(self, other: object) -> RuleGroup:
        if isinstance(other, RuleGroup):
            return RuleGroup((*self.rules, *other.rules))
        if isinstance(other, Rule):
            return RuleGroup((*self.rules, other))
        return NotImplemented

So far I've struggled to find a way of making this type generic properly.

This issue is related to #15 as this makes it harder to correctly type the Crossandra.__rules attribute.

@trag1c trag1c added the feature New feature or request label Aug 14, 2023
@trag1c trag1c added this to the Crossandra 2.1.0 milestone Aug 14, 2023
@trag1c trag1c added help wanted Contributions especially welcome improvement Code/documentation/DX improvements and removed feature New feature or request labels May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Contributions especially welcome improvement Code/documentation/DX improvements
Projects
None yet
Development

No branches or pull requests

1 participant