question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Forbid returning too long tuples

See original GitHub issue

Rule request

Thesis

Forbid returning a too long constant-length tuple from a function:

# bad
def hello():
  return 1, 2, 3, 4

When there are more than 2 values must be returned, use dataclasses.dataclass, typing.NamedTuple, or attrs instead.

Reasoning

Code readability and maintainability: the caller code must know exact order of all components which is easy to mess up. A real-world example:

time, phase, spacing, size, version, error, series_type = read_result_log()

😩

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
uhbif19commented, Mar 10, 2021

Please assign me, I am finishing PR for this task.

0reactions
orsiniumcommented, Mar 5, 2021

Exactly! I don’t see a reason why return is any different from yield from this perspective 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignoring part of a tuple returned in Python? - Stack Overflow
With the following code, is there any way to specify that I don't care about the 'address' part of the tuple returned?
Read more >
Returning and Consuming Tuples - Pluralsight
In this guide, we are going to look at how to create tuples in C#, how to return them from methods and how...
Read more >
Tuples are ok - DEV Community ‍ ‍
Long tuples can be a pain, the biggest reason is that with longer tuple its harder to remember at which position stands which...
Read more >
Code Smell:System.Tuple - Passion for Coding
Typical use of tuples include allowing multiple return values for functions or storing temporary data inside a method.
Read more >
Why not tuples? - Google Groups
solution is to disallow destructuring in a map assignment. ... I think there is no really big reason to make a special tuple...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found