NamedGeneric#
- class discopy.interaction.NamedGeneric[source]#
Bases:
Generic
[T
]A
NamedGeneric
is aGeneric
where the type parameter has a name.- Parameters:
attr – The name of the type parameter.
Note
In a standard
Generic
class, the type parameter disappears when the member of the class is instantiated, e.g.>>> assert list[int]([1, 2, 3])\ ... == list[float]([1, 2, 3])\ ... == [1, 2, 3]
In a
NamedGeneric
, the type parameter is attached to the members of the class so that we have access to it.Example
>>> from dataclasses import dataclass >>> @dataclass ... class L(NamedGeneric["dtype"]): ... inside: list >>> assert L[int]([1, 2, 3]).dtype == int >>> assert L[int]([1, 2, 3]) != L[float]([1, 2, 3])