ITADN

Error "open" is not a known attribute of module "io"

#8110Openjxu 创建于 2026-07-07
team needs to reproduce
J
jxucommented
<!-- Read the guidelines for filing an issue first. https://github.com/microsoft/pylance-release/blob/main/TROUBLESHOOTING.md#filing-an-issue --> ## Environment data <!-- To find your version, open the VS Code extensions panel, then locate Pylance from the list of installed extensions. The version appears next to the name. --> - Pylance version: 2026.2.1 - OS and version: Linux (VS Code Server / remote) - Python version (& distribution if applicable, e.g. Anaconda): 3.10.19 (/anaconda/envs/azureml_py310_sdkv2) ## Code Snippet <!-- Please provide a minimal, self-contained code snippet that reproduces the issue. If the code snippet uses any libraries, please specify the versions used. Note: If you think a GIF of what is happening would be helpful, consider tools like https://github.com/vkohaupt/vokoscreenNG, https://www.cockos.com/licecap/, https://github.com/phw/peek or https://www.screentogif.com/ . --> ```python import io io.open() ``` ## Expected behavior io.open() is an alias to open(), so shouldn't complain ## Actual behavior Produces error ## Extra Guess from Claude Opus 4.8: Expected: no error. io.open is valid and is the builtin open. Why this is a false positive — the stubs and runtime both declare it: - Runtime: import io; io.open is open → True (and import _io; _io.open is open → True). - Bundled typeshed stdlib/_io.pyi: - line 1: import builtins - line 19: open = builtins.open - Bundled typeshed stdlib/io.pyi: - line 20: from _io import (... open as open ...) ← redundant-alias re-export - line 27: open listed in __all__ So open is a public symbol of _io, re-exported by io via open as open and present in io.__all__ — yet Pyright 1.1.408 still reports it as unknown. Likely cause (hypothesis): Pyright isn't treating the module-level assignment form open = builtins.open in _io.pyi as a re-exportable symbol when io.pyi re-exports it with from _io import open as open. Possibly aggravated by the io ↔ _io circular import in the stubs (_io.pyi line 6 imports from io, io.pyi line 20 imports from _io). Note the sibling open_code is declared as a normal def in _io.pyi and does not trigger the error — only the assignment-aliased open does.
0 条评论