Skip to content

Make deque subscriptable? #3413

@JukkaL

Description

@JukkaL

Mypy doesn't let you write deque[int] etc., but the recommended replacement (typing.Deque) is not present in Python 3.6.0 typing:

from collections import deque

def f(x: 'deque[int]') -> None: pass  # deque not subscriptable, use typing.Deque

Maybe we should allow the above example since typing.Deque may be unavailable at runtime. Alternatively, we could modify the message to recommend using something like this:

MYPY = False
if MYPY:
    from typing import Deque
....

However, the above is pretty unintuitive. TYPE_CHECKING is not present in earlier versions of typing so it's not always an option, but we could perhaps recommend it.

[Zulip hit this issue recently.]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions