reportAssertAlwaysTrue.md
April 8, 2026 · View on GitHub
Overview
reportAssertAlwaysTrue is a Pylance and Pyright diagnostic that warns when an assert statement is always true, making the assertion redundant. This helps you identify unnecessary code and potential logic errors in your Python projects.
Representative Issues
- #3102: Ensure that default argument types in functions match the annotated parameter types to avoid runtime errors and type checking issues.
- #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.
Examples
# Warning: Assert expression always evaluates to true
# (a non-empty tuple is always truthy — did you mean to assert the contents?)
assert (1 != 2, "Error message")
c = (2, 3)
assert c # Warning: Assert expression always evaluates to true
Fix — assert the condition directly, not inside a tuple:
assert 1 != 2, "Error message" # OK: asserts the condition, not a tuple
Common Fixes & Workarounds
- Remove or update
assertstatements that are always true to avoid redundant code. - Double-check logic in assertions to ensure they are meaningful and not trivially true.
- Use explicit type annotations and consistent type stubs to avoid confusion.
- Refer to 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