MCPcopy Create free account
hub / github.com/astral-sh/ruff / check_tuple_unpacking

Method check_tuple_unpacking

crates/ruff_python_parser/src/parser/statement.rs:503–522  ·  view source on GitHub ↗

Report [`UnsupportedSyntaxError`]s for each starred element in `expr` if it is an unparenthesized tuple. This method can be used to check for tuple unpacking in `return`, `yield`, and `for` statements, which are only allowed after [Python 3.8] and [Python 3.9], respectively. [Python 3.8]: https://github.com/python/cpython/issues/76298 [Python 3.9]: https://github.com/python/cpython/issues/90881

(&mut self, expr: &Expr, kind: UnsupportedSyntaxErrorKind)

Source from the content-addressed store, hash-verified

501 /// [Python 3.8]: https://github.com/python/cpython/issues/76298
502 /// [Python 3.9]: https://github.com/python/cpython/issues/90881
503 pub(super) fn check_tuple_unpacking(&mut self, expr: &Expr, kind: UnsupportedSyntaxErrorKind) {
504 if kind.is_supported(self.options.target_version) {
505 return;
506 }
507
508 let Expr::Tuple(ast::ExprTuple {
509 elts,
510 parenthesized: false,
511 ..
512 }) = expr
513 else {
514 return;
515 };
516
517 for elt in elts {
518 if elt.is_starred_expr() {
519 self.add_unsupported_syntax_error(kind, elt.range());
520 }
521 }
522 }
523
524 /// Parses a `raise` statement.
525 ///

Callers 3

parse_for_statementMethod · 0.80

Calls 4

is_supportedMethod · 0.80
is_starred_exprMethod · 0.80
rangeMethod · 0.45

Tested by

no test coverage detected