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

Any plan for improving type hint #6404

Open
noTmiHoYo opened this issue Oct 22, 2022 · 1 comment
Open

Any plan for improving type hint #6404

noTmiHoYo opened this issue Oct 22, 2022 · 1 comment
Assignees
Labels
question Question on using Taichi

Comments

@noTmiHoYo
Copy link

I am using vscode with pylance. Autocomplete and typehint almost won't work..

Are there any one are current working on this? Or should I create a PR to fix some of these problems?

Several examples.

Example 1

PyLance cannot figure out what does VectorType stand for..
image

Example 2

image

possible fix for example 1&2: I found these problems are fixed after I add some import statement in __init__.py.

Example 3

ti.math.vec2(1, 2).x is valid. But no completion is provided.
possible fix: provide special type hint for vec2, vec3, vec4, ivec2, ivec3, etc..

Example 4

though ti.math.vec2 can be used as type when define a taichi struct, but it cannot be used in isinstance(ti.math.vec2(1, 2), ti.math.vec2) because it is not a real python type.
possible fix: How about make ti.types types real types inside C code ?

Example #5

when i try to access a member variable of a object of classes decorated by @ti.dataclass, no auto completion is provided.
possible fix: PEP 681

@noTmiHoYo noTmiHoYo added the question Question on using Taichi label Oct 22, 2022
@neozhaoliang
Copy link
Contributor

neozhaoliang commented Oct 24, 2022

Hi, you are welcome to contribute! The suggestions for these examples are very valuable.

Let me explain why vec2.x does not have an auto completion: this attribute is added to the Matrix class via a decorator: https://github.com/taichi-dev/taichi/blob/master/python/taichi/lang/matrix.py#L370
and hence the code autocompletion plugin needs to "run" this decorator to see it, which is infeasible.

@neozhaoliang neozhaoliang self-assigned this Oct 28, 2022
neozhaoliang pushed a commit that referenced this issue Nov 16, 2022
Issue: #6404 

### Brief Summary 

This PR doesn't solve the issue in #6404 but it helps a bit for
beginners.

Our type hint isn't perfect yet, but it should at least work for the
python apis. ;) Adding a faq so that users can find them.

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
…6621)

Issue: taichi-dev#6404 

### Brief Summary 

This PR doesn't solve the issue in taichi-dev#6404 but it helps a bit for
beginners.

Our type hint isn't perfect yet, but it should at least work for the
python apis. ;) Adding a faq so that users can find them.

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
question Question on using Taichi
Projects
Status: Todo
Development

No branches or pull requests

2 participants