This rule raises an issue when an assigned value type is not compatible with the type hint of the assigning variable.
Type hints in Python allow you to specify the expected types of variables and function return values. While type hints are not enforced at runtime, they serve as documentation and can be checked using static type checkers to catch type-related errors during development.
When an assigned value type is incompatible with the type hint of the assigning variable, it can lead to several issues:
Assign the variable to the value compatible with the type hint or change the type hint to be compatible with the variable’s type.
def my_function():
my_int: int = "string" # Noncompliant
def my_function():
my_str: str = "string"