def _least_general_unifier_generic(self, t1: GenericMeta, t2: GenericMeta): """Unify two generic types.""" if not _geqv(t1, t2): raise TypeInferenceError('bad unify') elif t1.__args__ is not None and t2.__args__ is not None: for a1, a2 in zip(t1.__args__, t2.__args__): return self.least_general_unifier(a1, a2)
def __new__(cls, *args, **kwds): if typing._geqv(cls, AsyncGenerator): raise TypeError( 'Type AsyncGenerator cannot be instantiated; ' 'create a subclass instead') return typing._generic_new( _collections_abc.AsyncGenerator, cls, *args, **kwds)
def _unify_generic(self, t1: GenericMeta, t2: GenericMeta): """Unify two generic-typed nodes.""" if not _geqv(t1, t2): raise TypeInferenceError('bad unify') elif t1.__args__ is not None and t2.__args__ is not None: for a1, a2 in zip(t1.__args__, t2.__args__): self.unify(a1, a2)
def can_unify(self, t1, t2): """Return true iff given argument types can be unified.""" if isinstance(t1, TypeVar) or isinstance(t2, TypeVar): return True elif isinstance(t1, GenericMeta) and isinstance(t2, GenericMeta): if not _geqv(t1, t2): return False elif t1.__args__ is not None and t2.__args__ is not None: for a1, a2 in zip(t1.__args__, t2.__args__): if not self.can_unify(a1, a2): return False return True else: return False elif isinstance(t1, GenericMeta): return False elif isinstance(t2, GenericMeta): return False elif t1.__class__.__name__ == '_Union' and t2.__class__.__name__ == 'Union': for union_type in t1.__args__: if union_type in t2.__args__: return True else: return False elif t1.__class__.__name__ == '_Union': if t2 in t1.__args__: return True else: return False elif t2.__class__.__name__ == '_Union': if t1 in t2.__args__: return True else: return False elif t1 == Any or t2 == Any: return True elif (hasattr(t1, 'msg') and ('not found' in t1.msg)) or (hasattr(t2, 'msg') and ('not found' in t2.msg)): return False elif isinstance(t1, _ForwardRef) and isinstance( t2, _ForwardRef) and t1 == t2: return True elif isinstance(t1, _ForwardRef) or isinstance(t2, _ForwardRef): return False elif issubclass(t1, t2) or issubclass(t2, t1): return True elif t1 != t2: return False else: return True
def can_unify(self, t1, t2): """Return true iff given argument types can be unified.""" if isinstance(t1, TypeVar) or isinstance(t2, TypeVar): return True elif isinstance(t1, GenericMeta) and isinstance(t2, GenericMeta): if not _geqv(t1, t2): return False elif t1.__args__ is not None and t2.__args__ is not None: for a1, a2 in zip(t1.__args__, t2.__args__): if not self.can_unify(a1, a2): return False return True else: False elif t1 != t2: return False else: return True
def __new__(cls, *args, **kwds): if typing._geqv(cls, Deque): return collections.deque(*args, **kwds) return typing._generic_new( collections.deque, cls, *args, **kwds)
def __new__(cls, *args, **kwds): if typing._geqv(cls, Counter): return collections.Counter(*args, **kwds) return typing._generic_new( collections.Counter, cls, *args, **kwds)
def __new__(cls, *args, **kwds): if typing._geqv(cls, ChainMap): return collections.ChainMap(*args, **kwds) return typing._generic_new( collections.ChainMap, cls, *args, **kwds)
def __new__(cls, *args, **kwds): if _geqv(cls, DefaultDict): return collections.defaultdict(*args, **kwds) return _generic_new(collections.defaultdict, cls, *args, **kwds)
def __new__(cls, *args, **kwds): if typing._geqv(cls, Deque): raise TypeError('Type Deque cannot be instantiated; use deque() instead') return typing._generic_new(deque, cls, *args, **kwds)
def __new__(cls, *args, **kwds): # noinspection PyProtectedMember if typing._geqv(cls, CounterTy): raise TypeError("Type CouterTy cannot be instantiated; " "use counter() instead") return Counter.__new__(cls, *args, **kwds)
def __new__(cls, *args, **kwargs): # noqa: ANN002,ANN003,ANN204 if _geqv(cls, OrderedDict): return collections.OrderedDict(*args, **kwargs) return _generic_new(collections.OrderedDict, cls, *args, **kwargs)
def __new__(cls, *args, **kwargs): # noqa: ANN002,ANN003,ANN204 if _geqv(cls, Counter): return collections.Counter(*args, **kwargs) return _generic_new(collections.Counter, cls, *args, **kwargs)
def __new__(cls, *args, **kwargs): # noqa: ANN002,ANN003,ANN204 if _geqv(cls, ChainMap): return collections.ChainMap(*args, **kwargs) return _generic_new(collections.ChainMap, cls, *args, **kwargs)
def __new__(cls, *args, **kwargs): if typing._geqv(cls, Deque): # type: ignore return collections.deque(*args, **kwargs) return collections.deque.__new__(cls, *args, **kwargs) # type: ignore