-
Notifications
You must be signed in to change notification settings - Fork 771
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
Usage of module-level symbols declared in stub files should not report private usage #2326
Comments
I remember now why I didn't include this as part of the earlier change for member variables and methods. The problem is that it's common to use underscore names for private (non-runtime) classes, TypeVars, and type aliases in type stubs. For example, look at So I think it's best to continue to treat symbols with names that begin with underscores as "private" when they appear in type stubs at the module level. If you have reason to override this in stubs that you use, you can disable the |
I understand why not all symbols that begin with underscores are considered public. But for cases like
Is there a way to disable the check on a line-by-line basis or only for certain symbols? Because I do want to keep the |
You can assign a local alias for the private usage and then use a from hashlib import _Hash as Hash # type: ignore import hashlib
Hash = hashlib._Hash # type: ignore |
The method requires some boilerplates to work: from __future__ import annotations
import hashlib
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from hashlib import _Hash as Hash # type: ignore
def do_hash(hash_obj: Hash) -> Hash:
...
The code is a little bit verbose for suppressing a single warning, but I think it works for my use case. Thanks for helping! |
Environment data
Language Server version: Pylance language server 2022.1.5 (pyright 8d096292)
Expected behaviour
Module-level symbols declared in stub files should not be reported
reportPrivateUsage
when used.Actual behaviour
Module-level symbols declared in stub files are reported
reportPrivateUsage
when used.Code Snippet
"_Hash" is private and used outside of the module in which it is declared
Notes
Some module-level symbols in stub files, e.g.,
hashlib._Hash
andcurses._CursesWindow
, are essential for writing type annotations. And I think they should be considered public interface.#1454 (comment) already address the similar problem for private class members.
This enhancement request is specifically for module-level symbols.
The text was updated successfully, but these errors were encountered: