Skip to content
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

add static type annotations #221

Merged
merged 1 commit into from
May 23, 2024
Merged

add static type annotations #221

merged 1 commit into from
May 23, 2024

Conversation

davidism
Copy link
Member

@davidism davidism commented May 23, 2024

Add static type annotation to the source and tests. Passes with mypy strict, pyright basic, and pyright --verifytypes. Add py.typed marker and classifier.

If Attachment.data is not given, an error is raised. The argument order is a bit weird, probalby because it makes more sense to read them in that order, but due to that data can be None in the signature, but must not be None when actually used.

If Attachment.content_type is not given, it is detected. mimetypes.guess_type is used on filename if filename is given. If that returns None, text/plain is used if data is a string, otherwise application/octet-stream is used. The code requires content_type to be set, but would previously just fail when building the message. This detection seemed preferrable to an error.

@davidism davidism linked an issue May 23, 2024 that may be closed by this pull request
@davidism davidism added this to the 0.10.0 milestone May 23, 2024
@davidism davidism merged commit 846a67e into main May 23, 2024
8 checks passed
@davidism davidism deleted the typing branch May 23, 2024 22:18
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Type annotations / type hints / stub files for mypy
1 participant