Skip to content

DOC: fix misleading SIM107 example (#22325) - #26973

Open
Joosboy wants to merge 1 commit into
astral-sh:mainfrom
Joosboy:docs/22325-sim107-example
Open

Joosboy wants to merge 1 commit into
astral-sh:mainfrom
Joosboy:docs/22325-sim107-example

Conversation

@Joosboy

@Joosboy Joosboy commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Closes #22325. Replaces the broken SIM107 documentation example that overwrites a return variable with one that correctly demonstrates a cleanup action in the finally block.

@astral-sh-bot
astral-sh-bot Bot requested a review from ntBre July 19, 2026 08:07
@astral-sh-bot

astral-sh-bot Bot commented Jul 19, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser MichaReiser added the documentation Improvements or additions to public-facing documentation label Jul 20, 2026

@ntBre ntBre left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks like an improvement, but I had an idea for making it slightly clearer, based on Micha's earlier suggestion.

First, I think this is complicated enough to justify a little extra explanation. Instead of the simple "Use instead:" I think we probably want to write something more like "Instead, move the return out of the finally clause and reserve the finally for any cleanup that must run regardless of other returns."

I also think an additional except arm like in Micha's suggestion would help, something like this for the "Instead..." example:

def process_data(data):
    try:
        return transform(data)
    except ValueError:
        return None
    except TypeError:
        log_error(data)
    finally:
        cleanup(data)
    return -1

but then we'd also need to update the initial example, so maybe just expanding the Instead... is fine with the example you have now. I just liked retaining the return -1 somewhere, but it requires a non-returning except arm to have any effect.

MateehUllah

This comment was marked as low quality.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to public-facing documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SIM107 documentation example may be misleading

4 participants