From c64f9d065bb74f5b88ea1091d207f3350a69ed86 Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Wed, 23 Oct 2024 07:11:51 -0700 Subject: [PATCH] unnecessary inheritance from ad-hoc protocol (#12882) --- stdlib/@tests/stubtest_allowlists/common.txt | 2 ++ stdlib/unittest/runner.pyi | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index 710c31d08..13024e94a 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -660,6 +660,8 @@ tkinter.Tk.splitlist tkinter.Tk.unsetvar tkinter.Tk.wantobjects tkinter.Tk.willdispatch +unittest.runner._WritelnDecorator.flush +unittest.runner._WritelnDecorator.write tkinter.font.Font.__getitem__ # Argument name differs (doesn't matter for __dunder__ methods) tkinter.Misc.grid_propagate # The noarg placeholder is a set value list diff --git a/stdlib/unittest/runner.pyi b/stdlib/unittest/runner.pyi index be546f423..393d03dfa 100644 --- a/stdlib/unittest/runner.pyi +++ b/stdlib/unittest/runner.pyi @@ -18,13 +18,16 @@ class _TextTestStream(_SupportsWriteAndFlush, Protocol): # _WritelnDecorator should have all the same attrs as its stream param. # But that's not feasible to do Generically # We can expand the attributes if requested -class _WritelnDecorator(_TextTestStream): +class _WritelnDecorator: def __init__(self, stream: _TextTestStream) -> None: ... def writeln(self, arg: str | None = None) -> str: ... def __getattr__(self, attr: str) -> Any: ... # Any attribute from the stream type passed to __init__ # These attributes are prevented by __getattr__ stream: Never __getstate__: Never + # Methods proxied from the wrapped stream object via __getattr__ + def flush(self) -> object: ... + def write(self, s: str, /) -> object: ... _StreamT = TypeVar("_StreamT", bound=_TextTestStream, default=_WritelnDecorator)