mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 21:05:08 +00:00
Format raise
statement (#5595)
## Summary This PR implements the formatting of `raise` statements. I haven't looked at the black implementation, this is inspired from from the `return` statements formatting. ## Test Plan The black differences with insta. I also compared manually some edge cases with very long string and call chaining and it seems to do the same formatting as black. There is one issue: ```python # input raise OsError( "aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa" ) from a.aaaaa(aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa).a(aaaa) # black raise OsError( "aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa" ) from a.aaaaa( aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa ).a( aaaa ) # ruff raise OsError( "aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa" ) from a.aaaaa( aksjdhflsakhdflkjsadlfajkslhfdkjsaldajlahflashdfljahlfksajlhfajfjfsaahflakjslhdfkjalhdskjfa ).a(aaaa) ``` But I'm not sure this diff is the raise formatting implementation. --------- Co-authored-by: Louis Dispa <ldispa@deezer.com>
This commit is contained in:
parent
93bfa239b7
commit
e7e2f44440
11 changed files with 409 additions and 130 deletions
|
@ -211,7 +211,7 @@ type CommentsMap<'a> = MultiMap<NodeRefEqualityKey<'a>, SourceComment>;
|
|||
/// The comments of a syntax tree stored by node.
|
||||
///
|
||||
/// Cloning `comments` is cheap as it only involves bumping a reference counter.
|
||||
#[derive(Clone, Default)]
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub(crate) struct Comments<'a> {
|
||||
/// The implementation uses an [Rc] so that [Comments] has a lifetime independent from the [crate::Formatter].
|
||||
/// Independent lifetimes are necessary to support the use case where a (formattable object)[crate::Format]
|
||||
|
@ -400,7 +400,7 @@ impl<'a> Comments<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[derive(Debug, Default)]
|
||||
struct CommentsData<'a> {
|
||||
comments: CommentsMap<'a>,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue