reportDuplicateImport is a Pylance and Pyright diagnostic that warns when the same module or symbol is imported more than once in your code. Duplicate imports can clutter your code and may lead to confusion or subtle bugs.
- #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. - #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.
- #4163: Ensure consistency in the use of type stubs between Pyright's CLI and Pylance settings, especially with
useLibraryCodeForTypes. - #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.
- #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.
import os
import os # Error: Import "os" is duplicated
from typing import List
from typing import List # Error: Import "List" is duplicatedFix — remove duplicate imports:
import os
from typing import ListFix — consolidate multiple imports from the same module:
# Before (not an error, but cleaner when consolidated):
from typing import List
from typing import Dict
# After:
from typing import Dict, List- Remove duplicate import statements for the same module or symbol.
- Consolidate imports at the top of your file for clarity and maintainability.
- Enable
python.analysis.indexingto improve auto-import suggestions and avoid accidental duplicates. - 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.
python.analysis.diagnosticSeverityOverrides— adjust or suppress this diagnosticpython.analysis.typeCheckingMode— controls which diagnostics are enabled by default