[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:
Brent Westbrook 2025-03-05 08:46:43 -05:00 committed by GitHub
parent 23fd4927ae
commit d0623888b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 404 additions and 0 deletions

View file

@ -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;