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

Missing type annotations in pyi files #3240

Closed
tailhook opened this issue Sep 4, 2018 · 7 comments
Closed

Missing type annotations in pyi files #3240

tailhook opened this issue Sep 4, 2018 · 7 comments

Comments

@tailhook
Copy link
Contributor

tailhook commented Sep 4, 2018

Mypy's errors are:

aiohttp/frozenlist.pyi:10: error: Missing type parameters for generic type
aiohttp/frozenlist.pyi:17: error: Function is missing a type annotation
aiohttp/frozenlist.pyi:19: error: Function is missing a type annotation
aiohttp/frozenlist.pyi:21: error: Function is missing a type annotation
aiohttp/frozenlist.pyi:29: error: Function is missing a type annotation for one or more arguments
aiohttp/frozenlist.pyi:30: error: Function is missing a type annotation for one or more arguments
aiohttp/frozenlist.pyi:31: error: Function is missing a type annotation for one or more arguments
aiohttp/frozenlist.pyi:32: error: Function is missing a type annotation for one or more arguments
aiohttp/frozenlist.pyi:33: error: Function is missing a type annotation for one or more arguments
aiohttp/frozenlist.pyi:34: error: Function is missing a type annotation for one or more arguments
aiohttp/signals.pyi:18: error: Function is missing a type annotation for one or more arguments

My mypy.ini:

[mypy]
check_untyped_defs = True
disallow_any_generics = True
disallow_untyped_defs = True
follow_imports = silent
strict_optional = True
warn_redundant_casts = True
warn_unused_ignores = True

I would make a PR, but I'm not sure how to test it. I see these errors in project using mypy and aiohttp. When I run mypy against aiohttp itself I get lots of errors, much more than what I'm willing to fix in a single PR :)

@webknjaz
Copy link
Member

webknjaz commented Sep 4, 2018

Ref #1749: annotations are being added gradually. I think you could coordinate with @asvetlov wrt this.

@asvetlov
Copy link
Member

asvetlov commented Sep 4, 2018

Heh, the full list is many times longer.
I'll address the issue in the next aiohttp releases

@tailhook
Copy link
Contributor Author

tailhook commented Sep 6, 2018

While fixing this, I have noted that Signal can't be type-safe in the current form, as far as I understand. The only way to make signal type-safe I've found is to only allow single argument. I.e. like this:

from typing import Any, Generic, TypeVar, Callable

from aiohttp.frozenlist import FrozenList


__all__ = ('Signal',)


_T = TypeVar('_T')


class Signal(FrozenList[Callable[[_T], None]], Generic[_T]):

    def __init__(self, owner: Any) -> None: ...

    def __repr__(self) -> str: ...

    async def send(self, arg: _T) -> None: ...

From quick grepping it looks like Signal is only used with a single argument in the aiohttp codebase, so it might make sense to fix it. What do you think?

@asvetlov
Copy link
Member

asvetlov commented Sep 6, 2018

@tailhook
Copy link
Contributor Author

tailhook commented Sep 6, 2018

Hm. Is there any chance that this will be fixed in mypy/typing? (and even if it is, will it be backported to previous python versions?)

on_response_prepare accepts two arguments: https://docs.aiohttp.org/en/stable/web_reference.html?highlight=on_response_prepare#aiohttp.web.Application.on_response_prepare

Note, that while unergonomic (and breaking change) tuple will work for this signal.

Otherwise, it looks like we're stuck with non-type-safe signals.

@asvetlov
Copy link
Member

asvetlov commented Oct 2, 2018

#3246 partially fixes the issue.

The final fix should be done as a part of work for #3293

@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants