-
Notifications
You must be signed in to change notification settings - Fork 133
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
Consider type hints for user inputs #393
Comments
Thanks for the kind words, and sorry you got tripped up by a breaking change. I'd really like to get type annotations into Anymail. I started looking into this a few years ago, but had trouble getting useful feedback from mypy and django-stubs at the time. (There might have been a problem using django-stubs with a library project that doesn't have a Django settings file, but my memory is hazy. I think both packages have improved quite a bit since then, so it's perhaps time to try again.) If you have experience with getting type checking working in Django projects (and it sounds like you do), I'd welcome the help. A reasonable first step might be something like getting mypy running in the project and then annotating AnymailMessageMixin? Typing But also, |
Thanks @medmunds - I'm happy to contribute! Just made an initial PR for enabling type hinting and fixed a few issues. There are more improvements to be made in the future but this is a good start. On type hinting esp_extra - I have one initial question, which is how is I don't think type hinting |
@medmunds your comment about |
All of the
My concern is less about uses of Do you know if Python typing supports the equivalent of TypeScript's "interface merging," where developers can redeclare an interface locally to add new fields? If so, something like that might be the easier way to handle |
Aha! I thought there was some magic going on somewhere. That's definitely hard for a reader to grok, but I suppose I would have started searching for I don't think Python has that functionality yet but something similar, a TypedDict with optional extra keys, might be available starting in Python 3.13: https://peps.python.org/pep-0728/ I also think users with type hints are pretty used to |
Thank you for maintaining this repo! It's been a fantastic resource for my sites.
I recently did a major upgrade and was bitten by a breaking change in v8, whereby SparkPost's
esp_extra
needed various settings to be nested inside of"options"
instead of at the top level of theesp_extra
dict. The issue was that this failed silently and I didn't read the changelog closely enough or pay close enough attention to the SparkPost esp_extra documentation.Simple example:
The issue I faced was that
transactional
and other settings as part ofesp_extra
were just ignored.I'd love to implement type hints for the SparkPost backend (or other backends if that's helpful) and that would be welcomed by maintainers. My idea is that having a type hint using
typing.TypedDict
would have prevented me from inputting the wrong shape of data into myAnymailMessage
.The text was updated successfully, but these errors were encountered: