-
Notifications
You must be signed in to change notification settings - Fork 429
feat(parser): use str for SES EmailStr when email_validator package is omitted #1259
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,21 @@ | ||
import logging | ||
import sys | ||
from datetime import datetime | ||
from typing import List, Optional | ||
from typing import List, NewType, Optional | ||
|
||
from pydantic import BaseModel, Field | ||
from pydantic.networks import EmailStr | ||
from pydantic.types import PositiveInt | ||
|
||
from ..types import Literal | ||
|
||
has_email_validator = "email_validator" in sys.modules | ||
|
||
if has_email_validator: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we're gonna need |
||
from pydantic.networks import EmailStr | ||
else: | ||
logging.warning("email_validator package is not installed") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initialize a logger and change it to debug, so we'll know where it comes from.
|
||
EmailStr = NewType("EmailStr", str) # type: ignore[no-redef, misc] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NewType has recently been converted to a class which means it'll have a runtime impact. Since we're looking at a string only IF someone didn't follow our recommended install, use a Type Alias instead. You can also bring this up to save a from pydantic import BaseModel
EmailStr = str
if has_email_validator:
from pydantic import EmailStr
class Email(BaseModel):
address: EmailStr
feedback_channel = Email("[email protected]")
print(feedback_channel.address) |
||
|
||
|
||
class SesReceiptVerdict(BaseModel): | ||
status: Literal["PASS", "FAIL", "GRAY", "PROCESSING_FAILED"] | ||
|
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 suspect this will always be False because Pydantic is loading it dynamically, and this will only be true afterwards. You'll need to check if the module is actually installed instead of loaded - I can't recall by heart a 3.6+ compatible way in
importlib
/pkg_resources
to do that. I can help look for that after I finish another doc PR this week