-
Notifications
You must be signed in to change notification settings - Fork 6
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
Literal type usage #11
Comments
Hi, I just checked out PEP-586, can you tell me where you plan to introduce it? Thank you. |
I'm uncertain why |
I think using from enum import Enum
from pydantic import BaseModel
class AssetType(Enum):
native = "native"
credit_alphanum4 = "credit_alphanum4"
credit_alphanum12 = "credit_alphanum12"
class DemoOp(BaseModel):
asset_type: AssetType
demo_op = DemoOp.parse_obj({'asset_type': 'credit_alphanum4'})
assert demo_op.asset_type == AssetType.credit_alphanum4
# If we use Literal here, the user still has to compare strings here
# assert demo_op.asset_type == 'credit_alphanum4' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Literal type was introduced with PEP 586 in Python 3.8 and can be used with Pydantic. With
typing-extensions
theLiteral
type can also be used in Python 3.6+.Would it be ok to introduce
Literal
?The text was updated successfully, but these errors were encountered: