Fix incorrect Parameter range for *args and **kwargs #10283
Fix incorrect Parameter range for *args and **kwargs #10283charliermarsh merged 4 commits intoastral-sh:mainfrom
Parameter range for *args and **kwargs #10283Conversation
There was a problem hiding this comment.
Is the diff supposed to be that big? I used the same version of lalrpop (0.20.0) to update this file
There was a problem hiding this comment.
Yeah, lalrpop loves to generate large diffs :(
|
Changing the ranges drips over the formatter. There are multiple places where the formatter goes back to introspecting the source to identify the comment placement and I fear that the code has now been written in a way that assumes the incorrect I've been able to identify a problematic example: (
lambda # comment 1
* # comment 2
x: # comment 3
x
)But I haven't yet been successful to narrow it down where the range handling is happening. I suspect that it is related to #10281 (CC: @dhruvmanila) but haven't been able to confirm it yet. I suspect that the relevant code is ruff/crates/ruff_python_formatter/src/other/parameters.rs Lines 357 to 644 in 0293908 |
|
I can rebase, regen, and merge this later. |
f54010c to
1aeb5c1
Compare
|
Thanks for the formatter fix! I rebased and regenerated the parser |
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| ANN003 | 4590 | 2295 | 2295 | 0 | 0 |
| ANN002 | 1846 | 923 | 923 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+3218 -3218 violations, +0 -0 fixes in 2 projects; 41 projects unchanged)
apache/airflow (+2275 -2275 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
+ airflow/api/auth/backend/default.py:38:19: ANN002 Missing type annotation for `*args` - airflow/api/auth/backend/default.py:38:20: ANN002 Missing type annotation for `*args` + airflow/api/auth/backend/default.py:38:26: ANN003 Missing type annotation for `**kwargs` - airflow/api/auth/backend/default.py:38:28: ANN003 Missing type annotation for `**kwargs` + airflow/api/auth/backend/deny_all.py:40:19: ANN002 Missing type annotation for `*args` - airflow/api/auth/backend/deny_all.py:40:20: ANN002 Missing type annotation for `*args` + airflow/api/auth/backend/deny_all.py:40:26: ANN003 Missing type annotation for `**kwargs` - airflow/api/auth/backend/deny_all.py:40:28: ANN003 Missing type annotation for `**kwargs` + airflow/api/auth/backend/kerberos_auth.py:153:19: ANN002 Missing type annotation for `*args` - airflow/api/auth/backend/kerberos_auth.py:153:20: ANN002 Missing type annotation for `*args` + airflow/api/auth/backend/kerberos_auth.py:153:26: ANN003 Missing type annotation for `**kwargs` - airflow/api/auth/backend/kerberos_auth.py:153:28: ANN003 Missing type annotation for `**kwargs` + airflow/api/auth/backend/session.py:41:19: ANN002 Missing type annotation for `*args` - airflow/api/auth/backend/session.py:41:20: ANN002 Missing type annotation for `*args` + airflow/api/auth/backend/session.py:41:26: ANN003 Missing type annotation for `**kwargs` - airflow/api/auth/backend/session.py:41:28: ANN003 Missing type annotation for `**kwargs` + airflow/api_connexion/endpoints/forward_to_fab_endpoint.py:102:14: ANN003 Missing type annotation for `**kwargs` - airflow/api_connexion/endpoints/forward_to_fab_endpoint.py:102:16: ANN003 Missing type annotation for `**kwargs` + airflow/api_connexion/endpoints/forward_to_fab_endpoint.py:108:15: ANN003 Missing type annotation for `**kwargs` - airflow/api_connexion/endpoints/forward_to_fab_endpoint.py:108:17: ANN003 Missing type annotation for `**kwargs` + airflow/api_connexion/endpoints/forward_to_fab_endpoint.py:114:15: ANN003 Missing type annotation for `**kwargs` - airflow/api_connexion/endpoints/forward_to_fab_endpoint.py:114:17: ANN003 Missing type annotation for `**kwargs` + airflow/api_connexion/endpoints/forward_to_fab_endpoint.py:121:16: ANN003 Missing type annotation for `**kwargs` - airflow/api_connexion/endpoints/forward_to_fab_endpoint.py:121:18: ANN003 Missing type annotation for `**kwargs` + airflow/api_connexion/endpoints/forward_to_fab_endpoint.py:128:17: ANN003 Missing type annotation for `**kwargs` - airflow/api_connexion/endpoints/forward_to_fab_endpoint.py:128:19: ANN003 Missing type annotation for `**kwargs` ... 3595 additional changes omitted for rule ANN003 + airflow/api_connexion/endpoints/forward_to_fab_endpoint.py:39:15: ANN002 Missing type annotation for `*args` - airflow/api_connexion/endpoints/forward_to_fab_endpoint.py:39:16: ANN002 Missing type annotation for `*args` + airflow/api_connexion/parameters.py:100:30: ANN002 Missing type annotation for `*args` - airflow/api_connexion/parameters.py:100:31: ANN002 Missing type annotation for `*args` + airflow/api_connexion/security.py:118:23: ANN002 Missing type annotation for `*args` - airflow/api_connexion/security.py:118:24: ANN002 Missing type annotation for `*args` + airflow/api_connexion/security.py:163:23: ANN002 Missing type annotation for `*args` - airflow/api_connexion/security.py:163:24: ANN002 Missing type annotation for `*args` + airflow/api_connexion/security.py:180:23: ANN002 Missing type annotation for `*args` ... 4515 additional changes omitted for project
bokeh/bokeh (+943 -943 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
+ examples/basic/data/ajax_source.py:34:26: ANN002 Missing type annotation for `*args` - examples/basic/data/ajax_source.py:34:27: ANN002 Missing type annotation for `*args` + examples/basic/data/ajax_source.py:34:33: ANN003 Missing type annotation for `**kwargs` - examples/basic/data/ajax_source.py:34:35: ANN003 Missing type annotation for `**kwargs` + examples/basic/data/server_sent_events_source.py:36:26: ANN002 Missing type annotation for `*args` - examples/basic/data/server_sent_events_source.py:36:27: ANN002 Missing type annotation for `*args` + examples/basic/data/server_sent_events_source.py:36:33: ANN003 Missing type annotation for `**kwargs` - examples/basic/data/server_sent_events_source.py:36:35: ANN003 Missing type annotation for `**kwargs` + examples/models/graphs.py:22:78: ANN003 Missing type annotation for `**kwargs` - examples/models/graphs.py:22:80: ANN003 Missing type annotation for `**kwargs` + src/bokeh/core/property/struct.py:58:24: ANN003 Missing type annotation for `**fields` - src/bokeh/core/property/struct.py:58:26: ANN003 Missing type annotation for `**fields` ... 971 additional changes omitted for rule ANN003 + src/bokeh/core/property/validation.py:93:14: ANN002 Missing type annotation for `*args` - src/bokeh/core/property/validation.py:93:15: ANN002 Missing type annotation for `*args` ... 1872 additional changes omitted for project
Changes by rule (2 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| ANN003 | 4590 | 2295 | 2295 | 0 | 0 |
| ANN002 | 1846 | 923 | 923 | 0 | 0 |
Formatter (stable)
✅ ecosystem check detected no format changes.
Formatter (preview)
✅ ecosystem check detected no format changes.
…#10283) ## Summary Fix astral-sh#10282 This PR updates the Python grammar to include the `*` character in `*args` `**kwargs` in the range of the `Parameter` ``` def f(*args, **kwargs): pass # ~~~~ ~~~~~~ <-- range before the PR # ^^^^^ ^^^^^^^^ <-- range after ``` The invalid syntax `def f(*, **kwargs): ...` is also now correctly reported. ## Test Plan Test cases were added to `function.rs`.
Summary
Fix #10282
This PR updates the Python grammar to include the
*character in*args**kwargsin the range of theParameterThe invalid syntax
def f(*, **kwargs): ...is also now correctly reported.Test Plan
Test cases were added to
function.rs.