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

Change level of nesting code #128740

Closed
wants to merge 1 commit into from
Closed

Change level of nesting code #128740

wants to merge 1 commit into from

Conversation

byBenPuls
Copy link

Make code easier to read by reducing the level of nesting. High levels of nesting make code more confusing and less readable.
For example:

if process.returncode == 0:
    return stdout.decode(*DECODE_ARGS)
else:
    raise CalledProcessError(
        process.returncode, args,
        stdout.decode(*DECODE_ARGS), stderr.decode(*DECODE_ARGS)
    )

We can remove else, simplify the code:

if process.returncode == 0:
    return stdout.decode(*DECODE_ARGS)
raise CalledProcessError(
    process.returncode, args,
    stdout.decode(*DECODE_ARGS), stderr.decode(*DECODE_ARGS)
)

Copy link

cpython-cla-bot bot commented Jan 11, 2025

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Jan 11, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@picnixz
Copy link
Member

picnixz commented Jan 11, 2025

This is a cosmetic change and we don't accept cosmetic changes (with a few exceptions). This is fine as it is and we prefer to avoid such changes to ease backports. I would recommend closing this as not planned (also, this is an internal script)

@byBenPuls byBenPuls closed this Jan 11, 2025
@mhsmith
Copy link
Member

mhsmith commented Jan 11, 2025

And let me explain as the person who wrote this code, I sometimes find the redundant else more readable, especially when its content is short. With the else, it's immediately obvious that the two blocks are mutually exclusive. Without the else, you have to look at the content of the block to discover that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants