-
-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat: rewrite enumerated literals as Enums #633
base: main
Are you sure you want to change the base?
Conversation
@juancarlospaco what's the benefits of using the |
It can check if the value is in the range of the enum, for extra safety. Enum can be a more correct representation of "enumerated string values". |
Co-authored-by: Joel Lee <lee.yi.jie.joel@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to leave this PR parked as when I test it locally in my existing app which makes use of the literals for type hint it breaks the type checking. This is a big breaking change and should be done at the next major version change.
Example of breaking changes: # this is now broken because "provider" is expecting a enum class instance
resp = await supabase.auth.link_identity(
{
"provider": "google",
"options": {"redirect_to": f"{request.base_url}auth/callback"},
}
) now becomes resp = await supabase.auth.link_identity(
{
"provider": Provider("google"),
"options": {"redirect_to": f"{request.base_url}auth/callback"},
}
) And a more full FastAPI function that uses hinting inside of the params async def confirm(
request: Request,
token_hash: str,
type: EmailOtpType = "email",
supabase: AClient = Depends(create_supabase),
):
try:
if token_hash and type:
if type == "recovery":
request.session["password_update_required"] = True
await supabase.auth.verify_otp(
params={"token_hash": token_hash, "type": type}
)
return {"message": "User signed in successfully."}
... now becomes async def confirm(
request: Request,
token_hash: str,
type: EmailOtpType | None = None,
supabase: AClient = Depends(create_supabase),
):
try:
if not isinstance(type, EmailOtpType):
type = EmailOtpType("email" if type is None else type)
if token_hash and type:
if type.value == "recovery":
request.session["password_update_required"] = True
await supabase.auth.verify_otp(
params={"token_hash": token_hash, "type": type}
)
return {"message": "User signed in successfully."}
... |
I agree with the parking, it can sleep for a while. 👍 |
What kind of change does this PR introduce?