@@ -6,7 +6,7 @@ from _typeshed import FileDescriptorOrPath, ReadableBuffer, WriteableBuffer
6
6
from collections .abc import Callable , Iterable , Iterator
7
7
from os import _Opener
8
8
from types import TracebackType
9
- from typing import IO , Any , BinaryIO , Literal , Protocol , TextIO , TypeVar , overload , type_check_only
9
+ from typing import IO , Any , BinaryIO , Generic , Literal , Protocol , TextIO , TypeVar , overload , type_check_only
10
10
from typing_extensions import Self
11
11
12
12
__all__ = [
@@ -173,12 +173,12 @@ class _WrappedBuffer(Protocol):
173
173
# def seek(self, offset: Literal[0], whence: Literal[2]) -> int: ...
174
174
# def tell(self) -> int: ...
175
175
176
- # TODO: Should be generic over the buffer type, but needs to wait for
177
- # TypeVar defaults.
178
- class TextIOWrapper (TextIOBase , TextIO ): # type: ignore[misc] # incompatible definitions of write in the base classes
176
+ _BufferT_co = TypeVar ( "_BufferT_co" , bound = _WrappedBuffer , default = _WrappedBuffer , covariant = True )
177
+
178
+ class TextIOWrapper (TextIOBase , TextIO , Generic [ _BufferT_co ] ): # type: ignore[misc] # incompatible definitions of write in the base classes
179
179
def __init__ (
180
180
self ,
181
- buffer : _WrappedBuffer ,
181
+ buffer : _BufferT_co ,
182
182
encoding : str | None = None ,
183
183
errors : str | None = None ,
184
184
newline : str | None = None ,
@@ -187,7 +187,7 @@ class TextIOWrapper(TextIOBase, TextIO): # type: ignore[misc] # incompatible d
187
187
) -> None : ...
188
188
# Equals the "buffer" argument passed in to the constructor.
189
189
@property
190
- def buffer (self ) -> BinaryIO : ...
190
+ def buffer (self ) -> _BufferT_co : ... # type: ignore[override]
191
191
@property
192
192
def closed (self ) -> bool : ...
193
193
@property
@@ -211,7 +211,7 @@ class TextIOWrapper(TextIOBase, TextIO): # type: ignore[misc] # incompatible d
211
211
def readline (self , size : int = - 1 , / ) -> str : ... # type: ignore[override]
212
212
def readlines (self , hint : int = - 1 , / ) -> list [str ]: ... # type: ignore[override]
213
213
# Equals the "buffer" argument passed in to the constructor.
214
- def detach (self ) -> BinaryIO : ...
214
+ def detach (self ) -> _BufferT_co : ... # type: ignore[override]
215
215
# TextIOWrapper's version of seek only supports a limited subset of
216
216
# operations.
217
217
def seek (self , cookie : int , whence : int = 0 , / ) -> int : ...
0 commit comments