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

Verify if there's a more intuitive or memory-efficient implementation for refinement types #5

Open
espetro opened this issue Oct 4, 2021 · 0 comments

Comments

@espetro
Copy link
Owner

espetro commented Oct 4, 2021

I'm not sure if the current implementation for refinement types is intuitive, or if even it's memory efficient. Currently, a refinement predicate is a class that inherits from RefinementPredicate, and has a type_guard method:

class EmptyPredicate(Generic[_C], RefinementPredicate):

    @staticmethod
    def type_guard(value: _C, *args: Tuple[Any, ...], **kwargs: Dict[str, Any]) -> TypeGuard[_C]:
        return len(value) == 0

from typing import List, Annotated

EmptyIntList = Annotated[List[int], EmptyPredicate[List[int]]]

Alternatives I've thought about:

  • RefinementPredicate classes should be instantiated with a self.value param. To improve memory management, they could use __slots__.
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

No branches or pull requests

1 participant