@@ -28,7 +28,7 @@ use ruff_python_ast::{
2828} ;
2929use ruff_source_file:: OneIndexed ;
3030use ruff_text_size:: { Ranged , TextRange } ;
31- use rustpython_common :: wtf8 :: Wtf8Buf ;
31+ use rustpython_wtf8 :: Wtf8Buf ;
3232// use rustpython_ast::located::{self as located_ast, Located};
3333use rustpython_compiler_core:: {
3434 Mode ,
@@ -3529,7 +3529,7 @@ impl EmitArg<bytecode::Label> for ir::BlockIdx {
35293529/// The code has been ported from `_PyCompile_CleanDoc` in cpython.
35303530/// `inspect.cleandoc` is also a good reference, but has a few incompatibilities.
35313531fn clean_doc ( doc : & str ) -> String {
3532- let doc = rustpython_common :: str :: expandtabs ( doc, 8 ) ;
3532+ let doc = expandtabs ( doc, 8 ) ;
35333533 // First pass: find minimum indentation of any non-blank lines
35343534 // after first line.
35353535 let margin = doc
@@ -3558,6 +3558,37 @@ fn clean_doc(doc: &str) -> String {
35583558 }
35593559}
35603560
3561+ // copied from rustpython_common::str, so we don't have to depend on it just for this function
3562+ fn expandtabs ( input : & str , tab_size : usize ) -> String {
3563+ let tab_stop = tab_size;
3564+ let mut expanded_str = String :: with_capacity ( input. len ( ) ) ;
3565+ let mut tab_size = tab_stop;
3566+ let mut col_count = 0usize ;
3567+ for ch in input. chars ( ) {
3568+ match ch {
3569+ '\t' => {
3570+ let num_spaces = tab_size - col_count;
3571+ col_count += num_spaces;
3572+ let expand = " " . repeat ( num_spaces) ;
3573+ expanded_str. push_str ( & expand) ;
3574+ }
3575+ '\r' | '\n' => {
3576+ expanded_str. push ( ch) ;
3577+ col_count = 0 ;
3578+ tab_size = 0 ;
3579+ }
3580+ _ => {
3581+ expanded_str. push ( ch) ;
3582+ col_count += 1 ;
3583+ }
3584+ }
3585+ if col_count >= tab_size {
3586+ tab_size += tab_stop;
3587+ }
3588+ }
3589+ expanded_str
3590+ }
3591+
35613592fn split_doc < ' a > ( body : & ' a [ Stmt ] , opts : & CompileOpts ) -> ( Option < String > , & ' a [ Stmt ] ) {
35623593 if let Some ( ( Stmt :: Expr ( expr) , body_rest) ) = body. split_first ( ) {
35633594 let doc_comment = match & * expr. value {
0 commit comments