reportUnusedImport.md
April 8, 2026 · View on GitHub
Overview
reportUnusedImport is a Pylance and Pyright diagnostic that warns when an imported module or symbol is not used anywhere in your code. Removing unused imports helps keep your code clean and can improve performance.
Representative Issues
- #1969: Ensure that
python.analysis.indexingis enabled to maintain an up-to-date index of available modules and symbols, which helps in providing accurate auto-import suggestions. - #2840: Enhance the static analysis capabilities of Pylance to include warnings for unused function parameters, similar to how it handles other unreferenced elements in the code.
- #3102: Ensure that default argument types in functions match the annotated parameter types to avoid runtime errors and type checking issues.
- #3793: Ensure that the configuration settings for Pylance/Pyright are correctly applied to suppress errors in Python library files.
- #3853: Configure Pylance's packageIndexDepths appropriately for packages and ensure the correct Python environment is active to enable accurate auto-import suggestions.
- #3855: Ensure Python indexing is enabled in VSCode settings to support auto-import functionality for external packages.
- #4012: To override the diagnostic severity for import cycles in a project using pyright, configure it globally rather than per file.
- #4163: Ensure consistency in the use of type stubs between Pyright's CLI and Pylance settings, especially with
useLibraryCodeForTypes. - #495: Utilize the
excludeproperty in Pyright's config file to prevent analysis of unwanted folders, ensuring smoother configuration and reduced diagnostics clutter. - #5200: Provide a configuration setting to allow users to customize diagnostic rule severities based on the type checking mode, improving the granularity of error reporting.
- #5887: Ensure that classes inheriting from abstract base classes implement all abstract methods.
- #6300: When configuring file exclusions in a Python project, it's crucial to accurately exclude unnecessary folders like .venv to improve performance.
- #715: When using generic types like dictionaries in Python, prefer the
typing.Dictsyntax over the olderdict[t, t]syntax to ensure compatibility across different Python versions.
Examples
Error:
import os # 'os' is imported but never used
from sys import argv # 'argv' is imported but never used
def main():
print("hello")
Fix — remove unused imports:
def main():
print("hello")
If the import is needed for re-export (e.g., in __init__.py), use the explicit re-export form:
from mymodule import MyClass as MyClass # Explicit re-export
Common Fixes & Workarounds
- Remove unused import statements from your code.
- Enable
python.analysis.indexingand configurepackageIndexDepthsfor better auto-import suggestions. - Use the
excludeproperty in your config to avoid analyzing unnecessary folders. - Ensure your configuration settings are correctly applied to suppress unnecessary errors.
- Refer to the Pyright configuration documentation for details on configuring or disabling this diagnostic.
See Also
python.analysis.indexing— enable indexing for better auto-import suggestionspython.analysis.diagnosticSeverityOverrides— adjust or suppress this diagnosticpython.analysis.typeCheckingMode— controls which diagnostics are enabled by default