reportIncompatibleVariableOverride.md
April 8, 2026 · View on GitHub
Overview
reportIncompatibleVariableOverride flags cases where a variable in a subclass does not match the type of the variable it overrides in the base class. This diagnostic helps ensure that subclass variables are compatible with their base class counterparts, improving code reliability and maintainability.
Representative Issues
- #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.
- #4777: Balance comprehensive exclusion with inclusion of necessary workspace components in
excludepaths. - #5200: Provide a configuration setting to allow users to customize diagnostic rule severities by type checking mode.
- #6300: Exclude unnecessary folders like .venv to improve performance.
- #1804: Report errors when generics are overridden with incompatible types.
- #2678: Ensure that overridden properties are explicitly typed to match the abstract base class declaration.
- #4367: Ensure that comments in TOML files use correct line endings and do not contain unsupported control characters.
- #6814: Ensure that overridden symbols in subclasses are correctly aligned with the base class definitions.
- #8862: Configure type checking settings to avoid false positive errors related to undefined variables.
Examples
class Base:
value: int = 0
class Child(Base):
value: str = "hello" # Error: Variable "value" overrides class "Base"
# with incompatible type "str" (base type: "int")
Fix — use a compatible type:
class Child(Base):
value: int = 42 # OK: same type as base class
Common Fixes & Workarounds
- Ensure that overridden variables in subclasses match the type of the base class variable.
- Add explicit type annotations to overridden variables.
- Align subclass definitions with base class definitions to avoid type violations.
- Exclude unnecessary folders from analysis to improve performance.
- 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