Returning unnamed tuple from function as a code smell

Please follow this template to help us specify this new rule:

  • Returning from a function multiple values in an unnamed way, makes it harder to understand the function signature and the meaning of each value
  • snippet of Noncompliant Code
    def foo():
      return 1, 2
  • snippet of Compilant Code (fixing the above noncompliant code)
from collections import namedtuple

Point = namedtuple('Point',['x','y'])

def foo():
  return Point(1, 2)

Hello @Lee_Elenbaas and welcome to this community!

First of all, sorry for the late reply.
Thank you for suggesting this rule! We really appreciate new rule ideas :slight_smile:

I think your suggestion makes a lot of sense, as your second example is indeed much more understandable/maintainable than the first.

However, I can see this rule raising a lot of issues. It’s also a slightly opinionated rule with which some people may disagree. We’ll need to investigate this impact and how we can integrate this rule into our products without inconveniencing those who may not be interested in it. I created the following ticket for that.


Thanks for taking into account my idea

it can not be on the default profile at this point in time - since a lot of code base will conflict with that code style suggestion
but it can be part of a profile that will encourage utilising optional typing to improve code readability
such profile could be relevant for other languages as well - like TypeScript - that has optional type system

such a profile will contain a set or rule like this one - that will enforce more usage of the typing system despite the fact that the language itself is loose in nature
it could be a good profile for companies that want the flexibility, of loosely typed languages together with the readability of strictly typed language