Skip to content

Problem subscripting asyncio.Future #835

Answered by hauntsaninja
ronf asked this question in Q&A
Discussion options

You must be logged in to vote

An else in your if TYPE_CHECKING block will make things nicer and obviate the need for quoting later:

if TYPE_CHECKING:
    _MyFuture = asyncio.Future[None]
else:
    _MyFuture = asyncio.Future

then just use _MyFuture in most places without quotes or worries.

There isn't really anything stubs can do about this... This is basically a problem with the runtime, which is why things are better in Python 3.9. (The only thing stubs could do is making Future not generic, but that would be the same as today's Future[Any])

Finally, if your minimum supported Python version is 3.7, in a lot of cases, from __future__ import annotations can ameliorate this class of problems. See https://mypy.readthedo…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@ronf
Comment options

@ronf
Comment options

Answer selected by ronf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants