Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Semantic syntax errors: better error message for global vs parameter#24902

Merged
sharkdp merged 1 commit into
mainfrom
david/global-parameter-msg
Apr 29, 2026
Merged

Semantic syntax errors: better error message for global vs parameter#24902
sharkdp merged 1 commit into
mainfrom
david/global-parameter-msg

Conversation

@sharkdp
Copy link
Copy Markdown
Contributor

@sharkdp sharkdp commented Apr 28, 2026

Summary

This is an attempt to improve the error message for something like

a = 1

def f(a):
    global a

I realize that the previous wording ("name 'a' is parameter and global") is used by CPython itself, but unless we are trying to be consistent with CPython, I think we can improve upon this? The previous version seemed a bit cryptic to me when I first saw it.

Test Plan

Updated snapshot tests

@sharkdp sharkdp added the diagnostics Related to reporting of diagnostics. label Apr 28, 2026
@astral-sh-bot astral-sh-bot Bot requested a review from ntBre April 28, 2026 13:23
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 28, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@carljm carljm removed their request for review April 28, 2026 20:09
@sharkdp sharkdp merged commit cf14481 into main Apr 29, 2026
50 checks passed
@sharkdp sharkdp deleted the david/global-parameter-msg branch April 29, 2026 06:46
thejchap pushed a commit to thejchap/ruff that referenced this pull request May 23, 2026
…stral-sh#24902)

## Summary

This is an attempt to improve the error message for something like
```py
a = 1

def f(a):
    global a
```

I realize that the previous wording ("name 'a' is parameter and global")
is used by CPython itself, but unless we are trying to be consistent
with CPython, I think we can improve upon this? The previous version
seemed a bit cryptic to me when I first saw it.

## Test Plan

Updated snapshot tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

diagnostics Related to reporting of diagnostics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants