Improve public API type annotations & fix unit test type errors #248
@xSAVIKx yes, 3.8 was working when I opened the PR. However because the repo has un-pinned dependencies in requirements.txt without a lockfile, some deps have new versions now that no longer work with 3.8. We can keep 3.8 but it will mean adding extra rules to requirements.txt to pin deps to old versions. I could do that if you prefer though. (Type checking was failing because of this when I made this change today.) |
I'd say pinning versions with Python version checks makes sense. And those were test dependencies only, right? |
Thanks a lot for your efforts @h4l 🙏 |
Python 3.8 is unsupported and dependencies (such as pydantic) are now shipping releases that fail to type check with mypy running in 3.8 compatibility mode. We run mypy in py 3.8 compatibility mode, so the mypy tox environments must only use deps that support 3.8. And unit tests run by py 3.8 must only use deps that support 3.8. To constrain the deps for 3.8 support, we use two constraint files, one for general environments that only constrains the dependencies that python 3.8 interpreters use, and another for mypy that constraints the dependencies that all interpreters use. Signed-off-by: Hal Blackburn <hwtb2@cam.ac.uk>
@xSAVIKx no problem!
There are two deps causing trouble at the moment,
|
Hey, thanks for the Python
cloudevents
library, I've been using it (viafunctions_framework
). In working with it I've noticed a few ways the types of your API could be tweaked to make things smoother for users. Also, while looking into the code, I noticed there were quite a few type errors in the test modules when running mypy, and mypy wasn't being run in CI to enforce the types. I figured I could help with that while offering some tweaks to the public API types.Changes
This PR:
@overload
s forfrom_binary
andfrom_structured
to correctly type the return when theevent_type
arg is NoneSet*()
methods oncloudevents.sdk.event.v1.Event
(previously you couldn't chain more than one call without type errors, as the return type did not haveSet*
methods)from_http()
conversion functions. They were requiring real dict types, so passing a headers object from an http request object would be a type error.from_dict()
) are now typed to takeMapping
rather than the exactdict
type, to allow passing dict-like objects, as well as read-only dicts.-> None:
function returns.One line description for the changelog
Improve public API type annotations, fix type errors in tests/examples and run type checks in CI
Tests pass
Appropriate changes to README are included in PR