org.sonar.l10n.py.rules.python.S6540.html Maven / Gradle / Ivy
Why is this an issue?
Being a dynamically typed language, the Python interpreter only does type checking during runtime. Getting the typing right is important as certain
operations may result in a TypeError
.
Type hints can be used to clarify the expected parameters of a function, enabling developers to better document its contract. Applying them
consistently makes the code easier to read and understand.
In addition, type hints allow some development environments to offer better autocompletion and improve the precision of static analysis tools.
How to fix it
Add a type hint to the function parameter.
Code examples
Noncompliant code example
def hello(name) -> str:
return 'Hello ' + name
Compliant solution
def hello(name: str) -> str:
return 'Hello ' + name
Resources
Documentation
© 2015 - 2024 Weber Informatics LLC | Privacy Policy