org.sonar.l10n.py.rules.python.S6543.html Maven / Gradle / Ivy
Why is this an issue?
Generic types, such as list
or dict
accept type arguments to specify the type of elements contained in the list or the
keys and values in the dictionary.
If a generic type is used without a type argument, the type arguments will implicitly assumed to be Any
. This makes the type hint less
informative and makes the contract of the function or variable annotated with the type hint more difficult to understand.
Furthermore, incomplete type hints can hinder IDE autocompletion and code insight capabilities of static analyis tools.
How to fix it
Add the missing type parameters to this generic type.
Code examples
Noncompliant code example
def print_list(numbers: list) -> None:
for n in numbers:
print(n)
Compliant solution
def print_list(numbers: list[int]) -> None:
for n in numbers:
print(n)
Resources
Documentation
© 2015 - 2024 Weber Informatics LLC | Privacy Policy