We have: # Concrete collection types. 'Dict', 'DefaultDict', 'List', 'Set', 'FrozenSet', 'NamedTuple', # Not really a type. 'Generator', But no mention of Deque. What this an intended omission? I would like to be able to write something like this: user_posts = defaultdict(deque) # type: DefaultDict[User, Deque[Post]]
I don't recall exactly what happened here, but I think it was left out during formulation of PEP 484 because it's not an ABC. IIRC originally we only wanted to include builtins and ABCs. But we changed that subsequently to include e.g. DefaultDict. I suppose we should change this now, but the cat is out of the bag for 3.6.0 and I would prefer not to change typing.py in any way between 3.6.0 and 3.5.3, so the best we could do would be to add it to 3.6.1 and 3.5.4 (whenever that will be). In the meantime collections.deque is generic, but that's only helpful in type comments, not in annotations. In a sense I wish we hadn't put typing.py in the stdlib, it would have been much simpler to fix this kind of issue. OTOH there are also advantages to having it in the stdlib, and anyways, it's too late to change, so we'll just have to suck it up (I certainly am).