aiohttp-cors
aiohttp-cors copied to clipboard
Add py.typed marker file
What do these changes do?
Type checkers look for a py.typed
file before doing type-checking on libraries imported by other code (see PEP 561).
Adding include_package_data=True
to setup.py means that the marker file will also be included in bdists (i.e. wheels), not just sdists.
Are there changes in behavior for the user?
Users who use mypy for type-checking will now be able to make use of the type hints in aiohttp-cors, i.e. if they are currently getting an error which looks like this:
error: Cannot find module named 'aiohttp_cors'
they will stop getting this error.
Related issue number
none
Checklist
- [x] I think the code is well written
- [ ] Unit tests for the changes exist – n/a
- [ ] Documentation reflects the changes – n/a
- [ ] Add a new news fragment into the
CHANGES
folder – whatCHANGES
folder?- name it
<issue_id>.<type>
(e.g.588.bugfix
) - if you don't have an
issue_id
change it to the pr id after creating the PR - ensure type is one of the following:
-
.feature
: Signifying a new feature. -
.bugfix
: Signifying a bug fix. -
.doc
: Signifying a documentation improvement. -
.removal
: Signifying a deprecation or removal of public API. -
.misc
: A ticket has been closed, but it is not of interest to users.
-
- Make sure to use full sentences with correct case and punctuation, for example:
Fix issue with non-ascii contents in doctest text files.
- name it
Typing marker is useless until we test typing correctness by mypy
tool along with unit tests run.
I know, now the library doesn't pass mypy
. Would you fix it as well?
I started fixing some of the annotations, but since I'm not sure how the library works I wasn't sure how to fix the rest of them. I'll have another look at the remaining problems (which are mostly where something returns an AbstractResource
, but a particular subclass (or a Union[Resource, StaticResource, ResourceRoute]
) is expected) later.
Remaining issues:
-
the signature of
ResourcesUrlDispatcherRouterAdapter.add_preflight_handler
is not compatible with the superclassAbstractRouterAdapter.add_preflight_handler
(webview
argument):https://github.com/aio-libs/aiohttp-cors/blob/73510a3a9212afd1d3740fd8b2feba63a1dcfe13/aiohttp_cors/urldispatcher_router_adapter.py#L137-L141
https://github.com/aio-libs/aiohttp-cors/blob/73510a3a9212afd1d3740fd8b2feba63a1dcfe13/aiohttp_cors/abc.py#L53-L56
-
several functions (
is_cors_for_resource
,add_preflight_handler
,set_config_for_routing_entity
) expect a particular kind of resource, but are passed anOptional[AbstractResource]
, which usually comes from aiohttp's type hints -
_request_resource
claims thatweb.AbstractRoute
/web.ResourceRoute
returns aweb.Resource
, but the aiohttp type hints don't agree
I think the last two issues might require modifications to aiohttp, and I don't know how you want to handle the first issue (presumably just add an ignored webview
argument to ResourcesUrlDispatcherRouterAdapter.add_preflight_handler
?). Personally I think the typing issues here are no greater than the typing issues with aiohttp itself at this point.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.