hygiene: fix mutable default argument in vttests/common.py::sgr_n (#19028)

sgr_n previously used a mutable list (`seq=[]`) as its default parameter.
In Python, default arguments are instantiated once at
function‐definition time and then shared across all calls.
If any caller mutated that list (e.g., `seq.append(...)`), later
invocations would inherit the mutated state, producing unpredictable or
corrupted VT-test sequences.
This commit is contained in:
S. M. Mohiuddin Khan Shiam 2025-06-25 01:19:22 +06:00 committed by GitHub
parent 1980e725ab
commit 3680e13bc0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -59,7 +59,18 @@ def clear_all():
def sgr(code=0):
csi('{}m'.format(code))
def sgr_n(seq=[]):
def sgr_n(seq=None):
"""Apply multiple SGR (Select Graphic Rendition) parameters.
Parameters
----------
seq : Iterable of int | None
Sequence of numeric SGR codes to emit. If ``None`` (default) an empty
sequence is assumed. A mutable default argument must be avoided to
prevent unwanted state sharing between calls.
"""
if seq is None:
seq = []
csi('{}m'.format(';'.join(str(code) for code in seq)))
def tbc():