Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initialising nested @ti.dataclass throws error when argument name not explicitly given #6884

Closed
AmesingFlank opened this issue Dec 13, 2022 · 0 comments · Fixed by #6949
Closed
Assignees

Comments

@AmesingFlank
Copy link
Collaborator

Consider this code snippet

import taichi as ti
ti.init(ti.cpu)


@ti.dataclass
class X:
    i: int


@ti.dataclass
class Y:
    x: X


x = X(0)
y = Y(x)

it fails with

  File "test.py", line 17, in <module>
    y = Y(x)
  File "/Users/dunfanlu/Code/Taichi/taichi/python/taichi/lang/struct.py", line 677, in __call__
    d[name] = dtype(args[index])
  File "/Users/dunfanlu/Code/Taichi/taichi/python/taichi/lang/struct.py", line 687, in __call__
    struct = self.cast(entries)
  File "/Users/dunfanlu/Code/Taichi/taichi/python/taichi/lang/struct.py", line 717, in cast
    entries[k] = int(
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Struct'

But if the final line y = Y(x) is replaced with y = Y(x=x), then it works.

@taichi-gardener taichi-gardener moved this to Untriaged in Taichi Lang Dec 13, 2022
@FantasyVR FantasyVR moved this from Untriaged to Todo in Taichi Lang Dec 16, 2022
@erizmr erizmr moved this from Todo to In Progress in Taichi Lang Dec 23, 2022
Repository owner moved this from In Progress to Done in Taichi Lang Dec 23, 2022
neozhaoliang added a commit that referenced this issue Dec 23, 2022
This PR close: #6884

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
quadpixels pushed a commit to quadpixels/taichi that referenced this issue May 13, 2023
This PR close: taichi-dev#6884

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants