When returning a tuple with a single element we get a false positive:
def tupling(value: tuple[int, ...] | int) -> tuple[int, ...]:
if isinstance(value, int):
return (value,)
return value
With sonar cloud and sonarlint we get python:S1721
Remove the parentheses after this "return" keyword.
This should be allowed as it is a valid use case since this is a tuple declaration and not parentheses uses for visual grouping. If we do return value,
, which is less readable, our auto formatter brings the parentheses back. Wrapping with tuple()
is overkill and actually slower.