I wanted to make a class for type hinting that the result of a function is a homogenous deque.
from typing import MutableSequence, T, _geqv from collections import deque class Deque(deque, MutableSequence[T], extra=deque): """A typing-like type for use with function signatures using deque's.""" def __new__(cls, *args, **kwds): if _geqv(cls, Deque): raise TypeError("Type Deque cannot be instantiated; " "use deque() instead") return deque.__new__(cls, *args, **kwds)
I basically copied the structure of similar code in the typing module. My question is, is this the correct way to do this?