(cls, *args, **kwargs)
| 1220 | |
| 1221 | |
| 1222 | def _generic_init_subclass(cls, *args, **kwargs): |
| 1223 | super(Generic, cls).__init_subclass__(*args, **kwargs) |
| 1224 | tvars = [] |
| 1225 | if '__orig_bases__' in cls.__dict__: |
| 1226 | error = Generic in cls.__orig_bases__ |
| 1227 | else: |
| 1228 | error = (Generic in cls.__bases__ and |
| 1229 | cls.__name__ != 'Protocol' and |
| 1230 | type(cls) != _TypedDictMeta) |
| 1231 | if error: |
| 1232 | raise TypeError("Cannot inherit from plain Generic") |
| 1233 | if '__orig_bases__' in cls.__dict__: |
| 1234 | tvars = _collect_type_parameters(cls.__orig_bases__, validate_all=True) |
| 1235 | # Look for Generic[T1, ..., Tn]. |
| 1236 | # If found, tvars must be a subset of it. |
| 1237 | # If not found, tvars is it. |
| 1238 | # Also check for and reject plain Generic, |
| 1239 | # and reject multiple Generic[...]. |
| 1240 | gvars = None |
| 1241 | basename = None |
| 1242 | for base in cls.__orig_bases__: |
| 1243 | if (isinstance(base, _GenericAlias) and |
| 1244 | base.__origin__ in (Generic, Protocol)): |
| 1245 | if gvars is not None: |
| 1246 | raise TypeError( |
| 1247 | "Cannot inherit from Generic[...] multiple times.") |
| 1248 | gvars = base.__parameters__ |
| 1249 | basename = base.__origin__.__name__ |
| 1250 | if gvars is not None: |
| 1251 | tvarset = set(tvars) |
| 1252 | gvarset = set(gvars) |
| 1253 | if not tvarset <= gvarset: |
| 1254 | s_vars = ', '.join(str(t) for t in tvars if t not in gvarset) |
| 1255 | s_args = ', '.join(str(g) for g in gvars) |
| 1256 | raise TypeError(f"Some type variables ({s_vars}) are" |
| 1257 | f" not listed in {basename}[{s_args}]") |
| 1258 | tvars = gvars |
| 1259 | cls.__parameters__ = tuple(tvars) |
| 1260 | |
| 1261 | |
| 1262 | def _is_dunder(attr): |
nothing calls this directly
no test coverage detected
searching dependent graphs…