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

Supporting Literal and enums in type validation #153

Open
ZeroIntensity opened this issue Feb 9, 2024 · 0 comments
Open

Supporting Literal and enums in type validation #153

ZeroIntensity opened this issue Feb 9, 2024 · 0 comments
Labels
advanced This should only be looked at by someone who knows what they're doing c api This has to do with the C API (_view) improvement Improvement to an existing feature
Milestone

Comments

@ZeroIntensity
Copy link
Owner

Improvement Description

As of now, typing.Literal nor enum.Enum are supported when using the type validation API. This is an important feature that should be ready before #10 is complete.

Improvement Request Example API

from view import compile_type
from enum import Enum

class MyEnum(Enum):
    A = 1
    B = 2

tp = compile_type(MyEnum)
tp.cast("1")  # MyEnum.A
tp.cast("A")  # MyEnum.A

And with literals:

from view import compile_type
from typing import Literal

tp = compile_type(Literal["a", "b", "c"])
tp.is_compatible("1")  # False
tp.is_compatible("a")  # True
tp.is_compatible("A")  # False

Anything else?

No response

@ZeroIntensity ZeroIntensity added improvement Improvement to an existing feature advanced This should only be looked at by someone who knows what they're doing c api This has to do with the C API (_view) labels Feb 9, 2024
@ZeroIntensity ZeroIntensity added this to the Beta Release milestone May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
advanced This should only be looked at by someone who knows what they're doing c api This has to do with the C API (_view) improvement Improvement to an existing feature
Projects
None yet
Development

No branches or pull requests

1 participant