@@ -117,9 +117,10 @@ def __init__(
117117 top_level_colon_align = None ,
118118 prefix_colon = None ,
119119 brace_single_entry_mapping_in_flow_sequence = None ,
120+ preserve_block_seqs_indents = None ,
120121 dumper = None ,
121122 ):
122- # type: (StreamType, Any, Optional[int], Optional[int], Optional[bool], Any, Optional[int], Optional[bool], Any, Optional[bool], Any) -> None # NOQA
123+ # type: (StreamType, Any, Optional[int], Optional[int], Optional[bool], Any, Optional[int], Optional[bool], Any, Optional[bool], Optional[bool], Any) -> None # NOQA
123124 self .dumper = dumper
124125 if self .dumper is not None and getattr (self .dumper , '_emitter' , None ) is None :
125126 self .dumper ._emitter = self
@@ -185,6 +186,8 @@ def __init__(
185186 # set to False to get "\Uxxxxxxxx" for non-basic unicode like emojis
186187 self .unicode_supplementary = sys .maxunicode > 0xFFFF
187188 self .sequence_dash_offset = block_seq_indent if block_seq_indent else 0
189+ self .preserve_block_seqs_indents = preserve_block_seqs_indents
190+ self .current_local_block_seq_indent = None
188191 self .top_level_colon_align = top_level_colon_align
189192 self .best_sequence_indent = 2
190193 self .requested_indent = indent # specific for literal zero indent
@@ -446,6 +449,7 @@ def expect_node(self, root=False, sequence=False, mapping=False, simple_key=Fals
446449 self .expect_scalar ()
447450 elif isinstance (self .event , SequenceStartEvent ):
448451 # nprint('@', self.indention, self.no_newline, self.column)
452+ self .current_local_block_seq_indent = self .event .block_seq_indent
449453 i2 , n2 = self .indention , self .no_newline # NOQA
450454 if self .event .comment :
451455 if self .event .flow_style is False and self .event .comment :
@@ -669,9 +673,12 @@ def expect_block_sequence_item(self, first=False):
669673 self .write_pre_comment (self .event )
670674 nonl = self .no_newline if self .column == 0 else False
671675 self .write_indent ()
672- ind = self .sequence_dash_offset # if len(self.indents) > 1 else 0
676+ cur_dash_offset = self .sequence_dash_offset
677+ if self .current_local_block_seq_indent and self .preserve_block_seqs_indents :
678+ cur_dash_offset = self .current_local_block_seq_indent
679+ ind = cur_dash_offset # if len(self.indents) > 1 else 0
673680 self .write_indicator (' ' * ind + '-' , True , indention = True )
674- if nonl or self . sequence_dash_offset + 2 > self .best_sequence_indent :
681+ if nonl or cur_dash_offset + 2 > self .best_sequence_indent :
675682 self .no_newline = True
676683 self .states .append (self .expect_block_sequence_item )
677684 self .expect_node (sequence = True )
0 commit comments