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

reportPrivateImportUsage is detected by pyright #329

Closed
yamap55 opened this issue Sep 14, 2021 · 4 comments
Closed

reportPrivateImportUsage is detected by pyright #329

yamap55 opened this issue Sep 14, 2021 · 4 comments

Comments

@yamap55
Copy link

yamap55 commented Sep 14, 2021

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
@ian-h-chamberlain
Copy link

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__.py uses 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.

@Poshi
Copy link

Poshi commented Oct 19, 2022

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) :-)

@NicoWeio
Copy link

#347 should fix this, once merged.

@sileht
Copy link
Collaborator

sileht commented Jan 30, 2023

This is fixed by #347.

@sileht sileht closed this as completed Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants