mirror of
https://github.com/microsoft/terminal.git
synced 2025-12-10 00:48:23 -06:00
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:
parent
1980e725ab
commit
3680e13bc0
@ -59,7 +59,18 @@ def clear_all():
|
|||||||
def sgr(code=0):
|
def sgr(code=0):
|
||||||
csi('{}m'.format(code))
|
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)))
|
csi('{}m'.format(';'.join(str(code) for code in seq)))
|
||||||
|
|
||||||
def tbc():
|
def tbc():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user