-
Notifications
You must be signed in to change notification settings - Fork 105
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
Using PEP695 type parameters syntax conflicts with TensorClass's bracket-based configuration.
To Reproduce
from tensordict import TensorClass
class A[T: int](TensorClass):
a: int
def do_thing(self, t: T) -> None:
...
class B[T: int](A[T]):
...
Traceback (most recent call last):
File "<python-input-29>", line 1, in <module>
class B[T: int](A[T]):
...
File "<python-input-29>", line 1, in <generic parameters of B>
class B[T: int](A[T]):
~^^^
File "/Users/.../python3.13/site-packages/tensordict/tensorclass.py", line 3072, in __getitem__
name = "_".join(item) # type: ignore
TypeError: sequence item 0: expected str instance, typing.TypeVar found```Similarly...
class B(A[int]):
...
Traceback (most recent call last):
File "<python-input-30>", line 1, in <module>
class B(A[int]):
~^^^^^
File "/Users/.../python3.13/site-packages/tensordict/tensorclass.py", line 3072, in __getitem__
name = "_".join(item) # type: ignore
TypeError: sequence item 0: expected str instance, type foundAnd finally...
class B(A["int"]):
...
Traceback (most recent call last):
File "<python-input-31>", line 1, in <module>
class B(A["int"]):
~^^^^^^^
File "/Users/.../python3.13/site-packages/tensordict/tensorclass.py", line 3077, in __getitem__
result = _TensorClassMeta( # type: ignore
cls_name,
...<2 lines>...
**{_item: True for _item in item},
)
File "/Users/.../python3.13/site-packages/tensordict/tensorclass.py", line 3032, in __new__
cls = super().__new__(mcs, name, bases, namespace, **kwargs)
File "<frozen abc>", line 106, in __new__
File "/Users/.../cpython-3.13.1-macos-aarch64-none/lib/python3.13/typing.py", line 1257, in _generic_init_subclass
super(Generic, cls).__init_subclass__(*args, **kwargs)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
TypeError: TensorClass_int.__init_subclass__() takes no keyword argumentsExpected behavior
Generics to have priority.
System info
Describe the characteristic of your environment:
- pip; uv venv
- 3.13.1
import tensordict, numpy, sys, torch
print(tensordict.__version__, numpy.__version__, sys.version, sys.platform, torch.__version__)
0.10.0 2.1.3 3.13.1 (main, Jan 5 2025, 06:22:40) [Clang 19.1.6 ] darwin 2.8.0Reason and Possible fixes
tensordict/tensordict/tensorclass.py
Line 3086 in 3e856cb
| def __getitem__(cls, item: IndexType) -> Self: |
Checklist
- I have checked that there is no similar issue in the repo (required)
- I have read the documentation (required)
- I have provided a minimal working example to reproduce the bug (required)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working