Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New rule - ban of abuse of tuple unpacking #13587

Open
spaceby opened this issue Oct 1, 2024 · 0 comments
Open

New rule - ban of abuse of tuple unpacking #13587

spaceby opened this issue Oct 1, 2024 · 0 comments
Labels
needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule

Comments

@spaceby
Copy link

spaceby commented Oct 1, 2024

In the project I work on, I sometimes find this

def the_name_is_too_long_for_two_of_them_to_fit_on_one_line(n):
    return n * 2


a_variable = 1
b_variable = 2

a_coefficient, b_coefficient = the_name_is_too_long_for_two_of_them_to_fit_on_one_line(a_variable), \
    the_name_is_too_long_for_two_of_them_to_fit_on_one_line(b_variable)

I found something like this once

def the_name_is_too_long_for_two_of_them_to_fit_on_one_line(n):
    return n * 2


a_variable = 1
b_variable = 2

a_coefficient, b_coefficient = (the_name_is_too_long_for_two_of_them_to_fit_on_one_line(item)
                                for item in (a_variable, b_variable))

In the first example, unpacking simply doesn't make sense.
In the second example, the code turned out shorter. But the price was understanding which variables lead to which result.

It's better to just do it like this:

def the_name_is_too_long_for_two_of_them_to_fit_on_one_line(n):
    return n * 2


a_variable = 1
b_variable = 2

a_coefficient = the_name_is_too_long_for_two_of_them_to_fit_on_one_line(a_variable)
b_coefficient = the_name_is_too_long_for_two_of_them_to_fit_on_one_line(b_variable)
@AlexWaygood AlexWaygood added rule Implementing or modifying a lint rule needs-decision Awaiting a decision from a maintainer labels Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

2 participants