reportPrivateImportUsage flags cases where imports from private modules or symbols are used in a way that exposes internal implementation details. This diagnostic helps enforce encapsulation and maintain a clean public API for your packages.
- #2943: Ensure that the use of '# type: ignore' comments is respected and correctly flagged by static analysis tools.
- #3003: Ensure Pylint plugins are installed and configured, and VSCode parses their diagnostics into editor warnings.
- #3102: Ensure that default argument types in functions match the annotated parameter types.
- #4163: Ensure consistency in the use of type stubs between Pyright's CLI and Pylance settings.
- #5200: Provide a configuration setting to allow users to customize diagnostic rule severities by type checking mode.
- #7001: Prefer 'openFilesOnly' diagnostic mode for large projects.
- #2277: Use alias imports to indicate public interface symbols in
py.typedlibraries. - #2639: Ensure symbols are explicitly re-exported if they should be part of the public API.
- #8377: Invoke Pyright with the project root directory for correct import resolution.
Error:
# some_package is a py.typed library.
# Its __init__.py imports helper from _internal without re-exporting it.
from some_package import helper # "helper" is not exported from "some_package"In a py.typed package, symbols imported into __init__.py are considered private unless they appear in __all__ or are re-exported using the import X as X pattern.
Fix — use the public API or import from the declared source:
from some_package._internal import helper # Import from the source module directlyOr ask the library maintainer to add helper to __all__ or re-export it explicitly.
- Avoid importing private modules or symbols unless necessary.
- Use alias imports and explicit re-exports to clarify your package's public API.
- Configure your project to use the correct root directory for import resolution.
- Use strict type checking and configure directories as needed in your config files.
- Review the Pyright configuration documentation for details on configuring or disabling this diagnostic.
python.analysis.diagnosticSeverityOverrides— adjust or suppress this diagnosticpython.analysis.typeCheckingMode— controls which diagnostics are enabled by default