org.sonar.l10n.py.rules.python.S6542.html Maven / Gradle / Ivy
The newest version!
Why is this an issue?
The type hint Any
represents any possible Python type, on which all operations are possible. This conveys the information that all
operations could be possible on a value annotated with Any
, making the value dynamically-typed.
Any
as a type hint provides no information about the expected type of the variable or parameter, essentially losing the benefits of
type hinting. This can make the code less clear and harder to understand and will reduce the code insight capabilities of IDEs and static analysis
tools.
How to fix it
Replace this use of Any
with a more specific type hint.
Code examples
Noncompliant code example
def foo(arg: Any) -> Any:
if isinstance(arg, int):
return arg + 1
else:
return arg.upper()
Compliant solution
def foo(arg: int | str) -> int | str:
if isinstance(arg, int):
return arg + 1
else:
return arg.upper()
Resources
Documentation
© 2015 - 2025 Weber Informatics LLC | Privacy Policy