reportPrivateImportUsage is detected by pyright
reportPrivateImportUsage is now detected in pyright 1.1.168. https://github.com/microsoft/pyright/releases/tag/1.1.168
I don't know much, but the cause seems to be an empty "tenacity/py.typed". #221
code
target code
from tenacity import (after_log, retry, retry_if_exception_type,
stop_after_attempt)
output
$ pyright a.py
Loading configuration file at /hoge/pyrightconfig.json
Auto-excluding **/node_modules
Auto-excluding **/__pycache__
Auto-excluding .git
stubPath /hoge/typings is not a valid directory.
Searching for source files
Found 1 source file
/hoge/a.py
/hoge/a.py:1:23 - error: "after_log" is not exported from module "tenacity"
Import from "tenacity.after" instead (reportPrivateImportUsage)
/hoge/a.py:1:41 - error: "retry_if_exception_type" is not exported from module "tenacity"
Import from "tenacity.retry" instead (reportPrivateImportUsage)
/hoge/a.py:2:23 - error: "stop_after_attempt" is not exported from module "tenacity"
Import from "tenacity.stop" instead (reportPrivateImportUsage)
/hoge/a.py:1:23 - error: Import "after_log" is not accessed (reportUnusedImport)
/hoge/a.py:1:34 - error: Import "retry" is not accessed (reportUnusedImport)
/hoge/a.py:1:41 - error: Import "retry_if_exception_type" is not accessed (reportUnusedImport)
/hoge/a.py:2:23 - error: Import "stop_after_attempt" is not accessed (reportUnusedImport)
7 errors, 0 warnings, 0 infos
version
$ pyright --version
pyright 1.1.168
$ pip freeze | grep tenacity
tenacity==8.0.1
From https://github.com/microsoft/pyright/blob/main/docs/typed-libraries.md#library-interface:
If they use the “import A as A” (a redundant module alias), “from X import A as A” (a redundant symbol alias), or “from . import A” forms, symbol “A” is not private unless the name begins with an underscore. If a file
__init__.pyuses the form “from .A import X”, symbol “A” is not private unless the name begins with an underscore (but “X” is still private).
A module can expose an
__all__symbol at the module level that provides a list of names that are considered part of the interface. The__all__symbol indicates which symbols are included in a wildcard import. All symbols included in the__all__list are considered public even if the other rules above would otherwise indicate that they were private. For example, this allows symbols whose names begin with an underscore to be included in the interface.'
These criteria seem a bit odd to me, but it sounds like adding an __all__ with the various exports or simply alias with from .A import X as X would probably be the least invasive way to "expose" the helpers, according to pyright. Presumably this would have no ill side effects as the exported name would be the same as it was previously.
Just coming here to say that I'm suffering the same issue with pylance (which is based in pyright, if I'm not wrong). I can ignore the errors, but it would be good to have a working export (in terms of static typing) :-)
#347 should fix this, once merged.
This is fixed by https://github.com/jd/tenacity/pull/347.