Skip to content

Composition of refinement predicates #2

@espetro

Description

@espetro

Currently, it is not possible to compose refinement predicates; for example:

from refined.predicates import NonEmpty, Contains
from typing import Annotated, Literal, List

NonEmptyListWithAZero = Annotated[List[int], NonEmpty[List[int]], Contains[List[Int], Literal[0]]]

However, you can define nested annotated types, which would return a composed annotated type with refinement predicates:

from refined.predicates import NonEmpty, Contains
from typing import Annotated, Literal, List

NonEmptyList = Annotated[List[int], NonEmpty[List[int]]]
ListWithAZero = Annotated[NonEmptyList,  Contains[List[Int], Literal[0]]]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions