-
Notifications
You must be signed in to change notification settings - Fork 769
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
reportGeneralTypeIssues
in pytorch
#4374
Comments
The The top-level import torch.backends |
@erictraut Thanks very much for the explanation! I'll ask the pytorch community. By the way, I'm curious if it's possible to re-export only |
It's possible to export the It's also possible for the top-level module to import and re-export the It all depends on how the torch maintainers want to define the library's public interface. |
The first changes the interface, and I'm afraid they would not adopt it. So is the second approach the only one to expose |
Or you can import the submodule explicitly in your code: |
Thanks! |
@erictraut is there any runtime check one can use to check if something is re-exported or not from
|
Not that I can think of. You could perhaps walk the AST for the parent module to look for nodes that use redundant import forms. That would work for some cases, but it wouldn't account for cases where a type stub is present. Out of curiosity, why do you want to verify this at runtime? Are you a library maintainer and want to validate this in a test? Or are you a library consumer? |
Is there a PEP describing why it's proper to expose it one way vs the another?
Because anything that is not covered by CI has a high probability of regressing again.
Former. |
There isn't a single PEP that covers this topic completely. PEP 484 introduced the concept of type stub files and described how imported symbols should be interpreted by type checkers within stub files. PEP 561 introduced the notion of "py.typed" libraries and indicated that it was up to library authors to decide whether to include type information inline or in stub files that ship with the library. (Most library authors have found that inlined type information is much easier to maintain, so that is by far the most typical approach.) PEP 561 unfortunately doesn't provide guidance about how imported symbols are meant to be interpreted by a type checker for a "py.typed" library. This topic has been discussed at length within the typing community, and we have converged on a set of rules that are now implemented in pyright. These rules can be found in the pyright documentation and also on the python/typing community site. Other type checkers, including mypy, have implemented parts of these rules, but there are gaps. For example, mypy doesn't support all of the documented ways to manipulate the In an effort to help library maintainers, I've added a mode to pyright that allows it to verify conformance and type completeness for a "py.typed" library. To use this mode, run I just tried running
Another validation approach that some library maintainers are adopting is the use of the Let me know if you run into any problems or have thoughts about how pyright (or tooling in general) could help you out here. |
I've addressed the issue that caused the hang when running |
Environment data
Code Snippet
Install pytorch:
torch==2.0.1+cu117
Additional Context
In
torch/__init__.py
there's a line:Expected behavior
No error.
Actual behavior
"backends" is not a known member of module "torch" Pylance(reportGeneralTypeIssues)
The text was updated successfully, but these errors were encountered: