-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Describe the bug
Pyright doesn't flag a non-aliased imported symbol as private.
To Reproduce
# sub.py (lib)
ONE = 1
TWO = 2# __init__.py (lib)
# ONE is re-exported, TWO is not.
from .sub import ONE as ONE, TWO
THREE = ONE + TWOWhere lib has a py.typed file as described in PEP 561.
# __main__.py (app)
import lib
print(lib.ONE, lib.TWO, lib.THREE)Expected behavior
According to:
pyright/docs/typed-libraries.md
Line 35 in cecb3e1
| * Imported symbols are considered private by default. 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 form “from .A import X”, symbol “A” is treated likewise. If a wildcard import (of the form “from X import *”) is used, all symbols referenced by the wildcard are not private. |
Modules and variables imported into the stub are not considered exported from the stub unless the import uses the
import ... as ...form or the equivalentfrom ... import ... as ...form. (UPDATE: To clarify, the intention here is that only names imported using the formX as Xwill be exported, i.e. the name before and after as must be the same.)
reportPrivateUsage (or another rule) should say that lib.TWO is private.
VS Code extension or command-line
Command line with this config:
[tool.pyright]
typeCheckingMode = "strict"
useLibraryCodeForTypes = trueversion: 1.1.166.
Additional context
mypy 0.910 correctly reports the issue:
app/__main__.py:3: error: Module has no attribute "TWO"