You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defcopy_with(self, args: object) ->Self: # type: ignore[override] # TODO: put in the overloads
),
)
class_IntersectionGenericAlias(_BasedGenericAlias, _root=True):
defcopy_with(self, args: object) ->Self: # type: ignore[override] # TODO: put in the overloadsreturncast(Self, Intersection[args])
def__eq__(self, other: object) ->bool:
ifnotisinstance(other, _IntersectionGenericAlias):
returnNotImplementedreturnset(self.__args__) ==set(other.__args__)
def__hash__(self) ->int:
returnhash(frozenset(self.__args__))
def__instancecheck__(self, obj: object) ->bool:
returnself.__subclasscheck__(type(obj))
def__subclasscheck__(self, cls: type[object]) ->bool:
returnall(issubclass(cls, arg) forarginself.__args__)
def__reduce__(self) -> (object, object):
func, (_, args) =super().__reduce__() # type: ignore[no-any-expr, misc]returnfunc, (Intersection, args)
ifsys.version_info> (3, 9):
@_BasedSpecialFormdefIntersection(self: _BasedSpecialForm, parameters: object) ->object:
"""Intersection type; Intersection[X, Y] means both X and Y. To define an intersection: - If using __future__.annotations, shortform can be used e.g. A & B - otherwise the fullform must be used e.g. Intersection[A, B]. Details: - The arguments must be types and there must be at least one. - None as an argument is a special case and is replaced by type(None). - Intersections of intersections are flattened, e.g.:: Intersection[Intersection[int, str], float] == Intersection[int, str, float] - Intersections of a single argument vanish, e.g.:: Intersection[int] == int # The constructor actually returns int - Redundant arguments are skipped, e.g.:: Intersection[int, str, int] == Intersection[int, str] - When comparing intersections, the argument order is ignored, e.g.:: Intersection[int, str] == Intersection[str, int] - You cannot subclass or instantiate an intersection. """ifparameters== ():
raiseTypeError("Cannot take an Intersection of no types.")
ifnotisinstance(parameters, tuple):
parameters= (parameters,)
msg="Intersection[arg, ...]: each arg must be a type."parameters=tuple(_type_check(p, msg) forpinparameters) # type: ignore[no-any-expr]parameters=_remove_dups_flatten(parameters) # type: ignore[no-any-expr]iflen(parameters) ==1: # type: ignore[no-any-expr]returnparameters[0] # type: ignore[no-any-expr]return_IntersectionGenericAlias(self, parameters) # type: ignore[arg-type, no-any-expr]else:
Intersection=_BasedSpecialForm(
"Intersection", doc="", alias=_IntersectionGenericAlias
)
class_TypeFormForm(_BasedSpecialForm, _root=True): # type: ignore[misc]def__init__(self, doc: str):
self._name="TypeForm"self._doc=self.__doc__=docdef__getitem__(self, parameters: object|tuple[object]) ->_BasedGenericAlias:
ifnotisinstance(parameters, tuple):
parameters= (parameters,)
return_BasedGenericAlias(self, parameters) # type: ignore[arg-type]TypeForm=_TypeFormForm(doc="""\ A type that can be used to represent a ``builtins.type`` or a ``SpecialForm``. For example: def f[T](t: TypeForm[T]) -> T: ... reveal_type(f(int | str)) # int | str """)
The text was updated successfully, but these errors were encountered:
parameters = _remove_dups_flatten(parameters) # type: ignore[no-any-expr]
if len(parameters) == 1: # type: ignore[no-any-expr]
return parameters[0] # type: ignore[no-any-expr]
return _IntersectionGenericAlias(self, parameters) # type: ignore[arg-type, no-any-expr]
basedtyping/basedtyping/__init__.py
Line 468 in 4a459f2
The text was updated successfully, but these errors were encountered: