mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-23 20:05:15 +00:00
[syntax-errors] Positional-only parameters before Python 3.8 (#16481)
Summary -- Detect positional-only parameters before Python 3.8, as marked by the `/` separator in a parameter list. Test Plan -- Inline tests.
This commit is contained in:
parent
23fd4927ae
commit
d0623888b3
6 changed files with 404 additions and 0 deletions
|
@ -3050,6 +3050,21 @@ impl<'src> Parser<'src> {
|
|||
// first time, otherwise it's a user error.
|
||||
std::mem::swap(&mut parameters.args, &mut parameters.posonlyargs);
|
||||
seen_positional_only_separator = true;
|
||||
|
||||
// test_ok pos_only_py38
|
||||
// # parse_options: {"target-version": "3.8"}
|
||||
// def foo(a, /): ...
|
||||
|
||||
// test_err pos_only_py37
|
||||
// # parse_options: {"target-version": "3.7"}
|
||||
// def foo(a, /): ...
|
||||
// def foo(a, /, b, /): ...
|
||||
// def foo(a, *args, /, b): ...
|
||||
// def foo(a, //): ...
|
||||
parser.add_unsupported_syntax_error(
|
||||
UnsupportedSyntaxErrorKind::PositionalOnlyParameter,
|
||||
slash_range,
|
||||
);
|
||||
}
|
||||
|
||||
last_keyword_only_separator_range = None;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue