reportRedeclaration.md
April 8, 2026 · View on GitHub
Overview
reportRedeclaration flags cases where a variable, function, or class is redeclared in a way that could cause confusion or errors. This diagnostic helps ensure that each symbol in your code has a clear and unique definition.
Representative Issues
- #10013: Explicitly declare attribute types at assignment to help type checkers recognize variable types.
- #7192: Avoid redeclaring variables with the same type to prevent shadowing and ensure clear variable identification.
- #8504: Ensure
FinalandTypeAliasare only used directly in type annotations without unsupported combinations.
Examples
Error:
MAX_RETRIES: int = 3
MAX_RETRIES: str = "three" # Redeclared with a different type
Fix — declare each variable once:
MAX_RETRIES: int = 3
Another common case — function redeclaration:
def process(x: int) -> int: ...
def process(x: str) -> str: ... # Redeclares 'process' (use @overload)
Fix with overloads:
from typing import overload
@overload
def process(x: int) -> int: ...
@overload
def process(x: str) -> str: ...
def process(x: int | str) -> int | str:
return x
Common Fixes & Workarounds
- Avoid redeclaring variables, functions, or classes with the same name in the same scope.
- Use unique names for new symbols to prevent shadowing.
- Refactor code to clarify symbol ownership and avoid accidental redeclaration.
- Review the Pyright configuration documentation for details on configuring or disabling this diagnostic.
See Also
python.analysis.diagnosticSeverityOverrides— adjust or suppress this diagnosticpython.analysis.typeCheckingMode— controls which diagnostics are enabled by default