Lines Matching refs:cls

275 def _check_generic(cls, parameters, elen):
276 """Check correct count for parameters of a generic cls (internal helper).
281 raise TypeError(f"{cls} is not a generic class")
284 raise TypeError(f"Too {'many' if alen > elen else 'few'} arguments for {cls};"
402 def __init_subclass__(cls, /, *args, **kwds):
473 def __subclasscheck__(self, cls):
512 def __new__(cls, *args, **kwargs):
513 if cls is Any:
515 return super().__new__(cls, *args, **kwargs)
1300 def __subclasscheck__(self, cls):
1572 def __subclasscheck__(self, cls):
1573 if isinstance(cls, _SpecialGenericAlias):
1574 return issubclass(cls.__origin__, self.__origin__)
1575 if not isinstance(cls, _GenericAlias):
1576 return issubclass(cls, self.__origin__)
1577 return super().__subclasscheck__(cls)
1677 def __subclasscheck__(self, cls):
1679 if issubclass(cls, arg):
1797 def __class_getitem__(cls, params):
1802 do `Foo[int]` - there, with `cls=Foo` and `params=int`.
1811 if cls in (Generic, Protocol):
1815 f"Parameter list to {cls.__qualname__}[...] cannot be empty"
1819 f"Parameters to {cls.__name__}[...] must all be type variables "
1823 f"Parameters to {cls.__name__}[...] must all be unique")
1826 for param in cls.__parameters__:
1829 params = prepare(cls, params)
1830 _check_generic(cls, params, len(cls.__parameters__))
1833 for param, new_arg in zip(cls.__parameters__, params):
1840 return _GenericAlias(cls, params,
1843 def __init_subclass__(cls, *args, **kwargs):
1846 if '__orig_bases__' in cls.__dict__:
1847 error = Generic in cls.__orig_bases__
1849 error = (Generic in cls.__bases__ and
1850 cls.__name__ != 'Protocol' and
1851 type(cls) != _TypedDictMeta)
1854 if '__orig_bases__' in cls.__dict__:
1855 tvars = _collect_parameters(cls.__orig_bases__)
1862 for base in cls.__orig_bases__:
1878 cls.__parameters__ = tuple(tvars)
1896 def _get_protocol_attrs(cls):
1903 for base in cls.__mro__[:-1]: # without object
1913 def _is_callable_members_only(cls):
1915 return all(callable(getattr(cls, attr, None)) for attr in _get_protocol_attrs(cls))
1919 cls = type(self)
1921 if cls._is_protocol:
1926 if cls.__init__ is not _no_init_or_replace_init:
1935 for base in cls.__mro__:
1938 cls.__init__ = init
1942 cls.__init__ = object.__init__
1944 cls.__init__(self, *args, **kwargs)
1975 def __instancecheck__(cls, instance):
1979 getattr(cls, '_is_protocol', False) and
1980 not getattr(cls, '_is_runtime_protocol', False) and
1986 if ((not getattr(cls, '_is_protocol', False) or
1987 _is_callable_members_only(cls)) and
1988 issubclass(instance.__class__, cls)):
1990 if cls._is_protocol:
1993 (not callable(getattr(cls, attr, None)) or
1995 for attr in _get_protocol_attrs(cls)):
2035 def __init_subclass__(cls, *args, **kwargs):
2039 if not cls.__dict__.get('_is_protocol', False):
2040 cls._is_protocol = any(b is Protocol for b in cls.__bases__)
2044 if not cls.__dict__.get('_is_protocol', False):
2048 if not getattr(cls, '_is_runtime_protocol', False):
2053 if not _is_callable_members_only(cls):
2063 for attr in _get_protocol_attrs(cls):
2081 if '__subclasshook__' not in cls.__dict__:
2082 cls.__subclasshook__ = _proto_hook
2085 if not cls._is_protocol:
2089 for base in cls.__bases__:
2096 if cls.__init__ is Protocol.__init__:
2097 cls.__init__ = _no_init_or_replace_init
2197 def __new__(cls, *args, **kwargs):
2201 def __class_getitem__(cls, params):
2214 def __init_subclass__(cls, *args, **kwargs):
2216 "Cannot subclass {}.Annotated".format(cls.__module__)
2220 def runtime_checkable(cls):
2239 if not issubclass(cls, Generic) or not cls._is_protocol:
2241 ' got %r' % cls)
2242 cls._is_runtime_protocol = True
2243 return cls
2858 def __new__(cls, typename, bases, ns):
2930 def __new__(cls, name, bases, ns, total=True):
2992 def __subclasscheck__(cls, other):
3151 def __init_subclass__(cls):
3152 subclass_name = cls.__name__
3330 def __getattribute__(cls, name):
3331 if name not in ("__dict__", "__module__") and name in cls.__dict__:
3333 f"{cls.__name__} is deprecated, import directly "
3334 f"from typing instead. {cls.__name__} will be removed "
3405 def create_model(cls: type[T]) -> type[T]:
3407 return cls