Upgrade RustPython (#5192)

## Summary

This PR upgrade RustPython to pull in the changes to `Arguments` (zip
defaults with their identifiers) and all the renames to `CmpOp` and
friends.
This commit is contained in:
Charlie Marsh 2023-06-19 17:09:53 -04:00 committed by GitHub
parent ddfdc3bb01
commit 36e01ad6eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
103 changed files with 1291 additions and 1165 deletions

View file

@ -14,21 +14,21 @@ pub(super) fn place_comment<'a>(
comment: DecoratedComment<'a>,
locator: &Locator,
) -> CommentPlacement<'a> {
handle_in_between_excepthandlers_or_except_handler_and_else_or_finally_comment(comment, locator)
.or_else(|comment| handle_match_comment(comment, locator))
.or_else(|comment| handle_in_between_bodies_own_line_comment(comment, locator))
.or_else(|comment| handle_in_between_bodies_end_of_line_comment(comment, locator))
.or_else(|comment| handle_trailing_body_comment(comment, locator))
.or_else(handle_trailing_end_of_line_body_comment)
.or_else(|comment| handle_trailing_end_of_line_condition_comment(comment, locator))
.or_else(|comment| {
handle_module_level_own_line_comment_before_class_or_function_comment(comment, locator)
})
.or_else(|comment| handle_positional_only_arguments_separator_comment(comment, locator))
.or_else(|comment| {
handle_trailing_binary_expression_left_or_operator_comment(comment, locator)
})
.or_else(handle_leading_function_with_decorators_comment)
handle_in_between_except_handlers_or_except_handler_and_else_or_finally_comment(
comment, locator,
)
.or_else(|comment| handle_match_comment(comment, locator))
.or_else(|comment| handle_in_between_bodies_own_line_comment(comment, locator))
.or_else(|comment| handle_in_between_bodies_end_of_line_comment(comment, locator))
.or_else(|comment| handle_trailing_body_comment(comment, locator))
.or_else(handle_trailing_end_of_line_body_comment)
.or_else(|comment| handle_trailing_end_of_line_condition_comment(comment, locator))
.or_else(|comment| {
handle_module_level_own_line_comment_before_class_or_function_comment(comment, locator)
})
.or_else(|comment| handle_positional_only_arguments_separator_comment(comment, locator))
.or_else(|comment| handle_trailing_binary_expression_left_or_operator_comment(comment, locator))
.or_else(handle_leading_function_with_decorators_comment)
}
/// Handles leading comments in front of a match case or a trailing comment of the `match` statement.
@ -138,8 +138,8 @@ fn handle_match_comment<'a>(
}
}
/// Handles comments between excepthandlers and between the last except handler and any following `else` or `finally` block.
fn handle_in_between_excepthandlers_or_except_handler_and_else_or_finally_comment<'a>(
/// Handles comments between except handlers and between the last except handler and any following `else` or `finally` block.
fn handle_in_between_except_handlers_or_except_handler_and_else_or_finally_comment<'a>(
comment: DecoratedComment<'a>,
locator: &Locator,
) -> CommentPlacement<'a> {
@ -147,7 +147,7 @@ fn handle_in_between_excepthandlers_or_except_handler_and_else_or_finally_commen
return CommentPlacement::Default(comment);
}
if let Some(AnyNodeRef::ExcepthandlerExceptHandler(except_handler)) = comment.preceding_node() {
if let Some(AnyNodeRef::ExceptHandlerExceptHandler(except_handler)) = comment.preceding_node() {
// it now depends on the indentation level of the comment if it is a leading comment for e.g.
// the following `elif` or indeed a trailing comment of the previous body's last statement.
let comment_indentation =
@ -627,11 +627,8 @@ fn handle_positional_only_arguments_separator_comment<'a>(
// ```python
// def test(a=10, /, b): pass
// ```
|| arguments
.defaults
.iter()
.position(|default| AnyNodeRef::from(default).ptr_eq(last_argument_or_default))
== Some(arguments.posonlyargs.len().saturating_sub(1));
|| are_same_optional(last_argument_or_default, arguments
.posonlyargs.last().and_then(|arg| arg.default.as_deref()));
if !is_last_positional_argument {
return CommentPlacement::Default(comment);
@ -906,7 +903,7 @@ fn last_child_in_body(node: AnyNodeRef) -> Option<AnyNodeRef> {
| AnyNodeRef::StmtWith(StmtWith { body, .. })
| AnyNodeRef::StmtAsyncWith(StmtAsyncWith { body, .. })
| AnyNodeRef::MatchCase(MatchCase { body, .. })
| AnyNodeRef::ExcepthandlerExceptHandler(ExcepthandlerExceptHandler { body, .. }) => body,
| AnyNodeRef::ExceptHandlerExceptHandler(ExceptHandlerExceptHandler { body, .. }) => body,
AnyNodeRef::StmtIf(StmtIf { body, orelse, .. })
| AnyNodeRef::StmtFor(StmtFor { body, orelse, .. })
@ -988,7 +985,7 @@ fn is_first_statement_in_enclosing_alternate_body(
}) => {
are_same_optional(following, handlers.first())
// Comments between the handlers and the `else`, or comments between the `handlers` and the `finally`
// are already handled by `handle_in_between_excepthandlers_or_except_handler_and_else_or_finally_comment`
// are already handled by `handle_in_between_except_handlers_or_except_handler_and_else_or_finally_comment`
|| handlers.is_empty() && are_same_optional(following, orelse.first())
|| (handlers.is_empty() || !orelse.is_empty())
&& are_same_optional(following, finalbody.first())

View file

@ -34,7 +34,7 @@ expression: comments.debug(test_case.source_code)
],
},
Node {
kind: ExcepthandlerExceptHandler,
kind: ExceptHandlerExceptHandler,
range: 100..136,
source: `except Exception as ex:⏎`,
}: {

View file

@ -39,7 +39,7 @@ expression: comments.debug(test_case.source_code)
],
},
Node {
kind: ExcepthandlerExceptHandler,
kind: ExceptHandlerExceptHandler,
range: 68..100,
source: `except Exception as ex:⏎`,
}: {

View file

@ -208,11 +208,11 @@ impl<'ast> PreorderVisitor<'ast> for CommentsVisitor<'ast> {
self.finish_node(comprehension);
}
fn visit_excepthandler(&mut self, excepthandler: &'ast Excepthandler) {
if self.start_node(excepthandler).is_traverse() {
walk_excepthandler(self, excepthandler);
fn visit_except_handler(&mut self, except_handler: &'ast ExceptHandler) {
if self.start_node(except_handler).is_traverse() {
walk_except_handler(self, except_handler);
}
self.finish_node(excepthandler);
self.finish_node(except_handler);
}
fn visit_format_spec(&mut self, format_spec: &'ast Expr) {
@ -250,12 +250,12 @@ impl<'ast> PreorderVisitor<'ast> for CommentsVisitor<'ast> {
self.finish_node(alias);
}
fn visit_withitem(&mut self, withitem: &'ast Withitem) {
if self.start_node(withitem).is_traverse() {
walk_withitem(self, withitem);
fn visit_with_item(&mut self, with_item: &'ast WithItem) {
if self.start_node(with_item).is_traverse() {
walk_with_item(self, with_item);
}
self.finish_node(withitem);
self.finish_node(with_item);
}
fn visit_match_case(&mut self, match_case: &'ast MatchCase) {