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
Add missing Type Hints
to torch. issue #7318
#8845
Conversation
torch/_torch_docs.py
Outdated
@@ -68,7 +69,7 @@ def parse_kwargs(desc): | |||
returned tensor. Default: ``False``. | |||
""") | |||
|
|||
add_docstr(torch.abs, | |||
add_docstr(_C.abs, |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
{"saddmm", (PyCFunction)THPVariable_sspaddmm, METH_VARARGS | METH_KEYWORDS, NULL}, | ||
{"sparse_coo_tensor", (PyCFunction)THPVariable_sparse_coo_tensor, METH_VARARGS | METH_KEYWORDS, NULL}, | ||
{"spmm", (PyCFunction)THPVariable_mm, METH_VARARGS | METH_KEYWORDS, NULL}, | ||
{"tensor", (PyCFunction)THPVariable_tensor, METH_VARARGS | METH_KEYWORDS, NULL}, |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@@ -186,7 +186,7 @@ def should_bind(declaration): | |||
|
|||
py_torch_functions = group_declarations_by_name(declarations, should_bind) | |||
|
|||
env = create_python_bindings(py_torch_functions, has_self=False) | |||
env = create_python_bindings(py_torch_functions, has_self=False, is_module=True) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
torch/__init__.py
Outdated
@@ -186,6 +186,7 @@ def set_default_dtype(d): | |||
from .tensor import Tensor | |||
from .storage import _StorageBase | |||
|
|||
tensor = _C.tensor # remove duplicate name, and fix to shortcut function |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Thank you for the PR, @kimdwkimdw! What is the general strategy for this PR? From what I can tell it looks like you're removing METH_STATIC, but why does that affect how pycharm can read the code? |
@zou3519 , Thank you for comment! First, here is my concept of gist, From 0.4.0, all methods in torch_functions goes to
The shorthand of above is that all methods are not imported with pythonic way. I want to import all methods via below code.
https://docs.python.org/3/c-api/structures.html#METH_STATIC When we import module methods like below,
IDE will run There is an important sentence.
I read all codes related in pytorch-0.3.0, pytorch-0.4.0, pytorch-master. |
@@ -186,7 +189,10 @@ def should_bind(declaration): | |||
|
|||
py_torch_functions = group_declarations_by_name(declarations, should_bind) | |||
|
|||
env = create_python_bindings(py_torch_functions, has_self=False) | |||
if PY2: |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
@kimdwkimdw I'm not very familiar with what we're doing with METH_STATIC and what PyModule_AddFunctions is doing. Someone (probably me) will have to sit down and read the specs for these things for a bit, I will get back to you soon after I understand this a little more |
@zou3519 👍 I'll think about better solution and substitute for PY2. |
Sorry for the delay in reviewing, @kimdwkimdw. I will get to it soon |
@kimdwkimdw I wonder if making i.e.
|
@zou3519 I'm not sure. But, I don't think that can solve its problem easily. Originally, I think we can think multiple solutions
Too lots of code change are needed
Also too lots of code change are needed
|
I tried (2), it's a little painful to get it to work. For (1), we have this problem that we're dumping all functions into torch._C. It would be nice to do some namespacing and put the variable functions into torch._C.VariableFunctions or something, where VariableFunctions is not a class. |
Is this going to be merged anytime soon? |
Generated We're using https://github.com/JetBrains/intellij-community/blob/master/python/helpers/generator3.py to generate stubs for binaries. I have not investigated yet what is the difference between doing so for released pytorch and pytorch with changes in this PR applied. |
anyone can help solve this issue? I almost give up pytorch for the boken type hints |
I'm having the same type hints problem with pytorch 1.0.0 |
I have a workshop coming up where people want to use them, so I'll refresh my PR for the typehints before early next week. I'll send a link for the PYI for 1.0 when I have it. |
This PR was subsumed by @t-vi's PR #12500, which has been merged to master. I'm going to close this PR. @kimdwkimdw, thank you for your hard work here, and your patience. It might still be worth incorporating some of the ideas from this patch when we (some day in the unforseeable future) become Python 3 only. For example, it seems like a generally good idea to bind functions as functions, not static methods. I've filed #16573 to keep track of this. |
#7318
Trying to fix #7318.
I fixed all issues except PY2.