Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Feature/implement mypy type checking #394
base: main
Are you sure you want to change the base?
Feature/implement mypy type checking #394
Changes from 6 commits
ebc2e88
a31f631
dfe7836
bac6cca
ae58e39
68732e6
3748cdf
97fe791
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
👍 it already found a bug!
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.
Another option here would be to replace the try/catch with
if isinstance(send_at, datetime)
.Question: Would you suggest first adding the type:ignore comments without changing code, and then going back to resolve each of them in later commits that change the code?
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.
If there's an easy fix I'd recommend doing it now - I just didn't see the fix offhand and lean towards keeping MyPy from slowing things down vs. trying to figure out a type hint I can't grok right away, especially if I know the code is fine.
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.
Is this necessary? (It doesn't seem to be referenced anywhere.)
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.
In my experimenting, I was able to switch
ignore_missing_imports
back toFalse
by:pip install -e '.[amazon-ses,resend,postal]'
in the workflow, to pick up all the optional dependencies (see earlier comment)boto3-stubs[s3,ses,sns]
to requirements-dev.txt to pick up boto3 typing (see later comment)_LazyImportError
s in webhooks/amazon_ses.py and webhooks/resend.py (like the ones you already added to webhooks/postal.py).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.
That sounds great!
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.
requests
should not be needed here, since it's already a package dependency. (But you need topip install -e .
to pick up package dependencies, per earlier comment.)However, I did need to add
boto3-stubs[s3,ses,sns]
since boto3 isn't typed.Question: How do library packages typically handle dependencies only needed for typing? Would it be helpful for django-anymail to declare a "typing" extra (
pip install django-anymail[typing]
) that adds the dependencies on django-stubs and boto3-stubs? Or do libraries usually assume that users will figure out on their own what typing stubs are required?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.
Hmmm, for me this was just for my local environment. I generally expect to
pip install -r requirements-dev.txt
and my local machine would have the necessary packages to run a command likemypy .
...that's what led me to make this change.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.
This change is no longer required (since you disabled mypy on tests).
But it raises a couple of questions: A lot of the tests use Anymail's added attributes directly on Django's EmailMessage or EmailMultiAlternatives, because this is a documented Anymail feature. (Anymail has always allowed duck typing for its added attributes.)
AnymailMessageProtocol
?)