@@ -28,7 +28,7 @@ use ruff_python_ast::{
28
28
} ;
29
29
use ruff_source_file:: OneIndexed ;
30
30
use ruff_text_size:: { Ranged , TextRange } ;
31
- use rustpython_common :: wtf8 :: Wtf8Buf ;
31
+ use rustpython_wtf8 :: Wtf8Buf ;
32
32
// use rustpython_ast::located::{self as located_ast, Located};
33
33
use rustpython_compiler_core:: {
34
34
Mode ,
@@ -3529,7 +3529,7 @@ impl EmitArg<bytecode::Label> for ir::BlockIdx {
3529
3529
/// The code has been ported from `_PyCompile_CleanDoc` in cpython.
3530
3530
/// `inspect.cleandoc` is also a good reference, but has a few incompatibilities.
3531
3531
fn clean_doc ( doc : & str ) -> String {
3532
- let doc = rustpython_common :: str :: expandtabs ( doc, 8 ) ;
3532
+ let doc = expandtabs ( doc, 8 ) ;
3533
3533
// First pass: find minimum indentation of any non-blank lines
3534
3534
// after first line.
3535
3535
let margin = doc
@@ -3558,6 +3558,37 @@ fn clean_doc(doc: &str) -> String {
3558
3558
}
3559
3559
}
3560
3560
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
+
3561
3592
fn split_doc < ' a > ( body : & ' a [ Stmt ] , opts : & CompileOpts ) -> ( Option < String > , & ' a [ Stmt ] ) {
3562
3593
if let Some ( ( Stmt :: Expr ( expr) , body_rest) ) = body. split_first ( ) {
3563
3594
let doc_comment = match & * expr. value {
0 commit comments