Skip to content

Commit 6d7173b

Browse files
srittauJelleZijlstra
authored andcommitted
Add StringIO.name and BytesIO.name (#1802)
Also, change the type of StringIO.name (Python 3) from str to Any. Neither StringIO nor BytesIO actually define a name field, but the super-class IO[T] of both in typeshed does define a read-only property. This means that sub-classes of StringIO and BytesIO adding this field will not typecheck correctly. Closes: #1790
1 parent a08d578 commit 6d7173b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

stdlib/2/_io.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ class BytesIO(_BufferedIOBase):
8282
def __init__(self, initial_bytes: bytes = ...) -> None: ...
8383
def __setstate__(self, tuple) -> None: ...
8484
def __getstate__(self) -> tuple: ...
85+
# BytesIO does not contain a "name" field. This workaround is necessary
86+
# to allow BytesIO sub-classes to add this field, as it is defined
87+
# as a read-only property on IO[].
88+
name: Any
8589
def getvalue(self) -> bytes: ...
8690
def write(self, s: bytes) -> int: ...
8791
def writelines(self, lines: Iterable[bytes]) -> None: ...
@@ -148,6 +152,10 @@ class StringIO(_TextIOBase):
148152
newline: Optional[unicode] = ...) -> None: ...
149153
def __setstate__(self, state: tuple) -> None: ...
150154
def __getstate__(self) -> tuple: ...
155+
# StringIO does not contain a "name" field. This workaround is necessary
156+
# to allow StringIO sub-classes to add this field, as it is defined
157+
# as a read-only property on IO[].
158+
name: Any
151159
def getvalue(self) -> unicode: ...
152160

153161
class TextIOWrapper(_TextIOBase):

stdlib/3/io.pyi

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ class FileIO(RawIOBase):
9898
# TODO should extend from BufferedIOBase
9999
class BytesIO(BinaryIO):
100100
def __init__(self, initial_bytes: bytes = ...) -> None: ...
101+
# BytesIO does not contain a "name" field. This workaround is necessary
102+
# to allow BytesIO sub-classes to add this field, as it is defined
103+
# as a read-only property on IO[].
104+
name: Any
101105
def getvalue(self) -> bytes: ...
102106
if sys.version_info >= (3, 2):
103107
def getbuffer(self) -> memoryview: ...
@@ -251,7 +255,10 @@ class TextIOWrapper(TextIO):
251255
class StringIO(TextIOWrapper):
252256
def __init__(self, initial_value: str = ...,
253257
newline: Optional[str] = ...) -> None: ...
254-
name = ... # type: str
258+
# StringIO does not contain a "name" field. This workaround is necessary
259+
# to allow StringIO sub-classes to add this field, as it is defined
260+
# as a read-only property on IO[].
261+
name: Any
255262
def getvalue(self) -> str: ...
256263
def __enter__(self) -> 'StringIO': ...
257264

0 commit comments

Comments
 (0)