You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
io.RawIOBase and typing.IO signatures differ #108411
But isn't RawIOBase supposed to be IO[bytes]? At least that's how I understood it.
I think a breaking change could be fine if it resolves a self-contradiction. In my opinion, the typing signature should be adjusted. But I am sure there are people with more knowledge on this subject than me ;)
Maybe we should also make the runtime parameter positional-only. It's technically a compatibility break, but it's unlikely to affect a lot of people, and the parameter is positional-only on the most common practical IO types.
Additionally, RawIOBase.read checks for null, so should the type hint be Optional[int]?
Child classes can have a broader parameter type than their parent class, so if you implement both io.RawIOBase and typing.IO, it's OK to use int | None as the argument type even if one of the base classes only allows int. Maybe we should have used int | None in typing.IO, but changing this now is more likely to break existing subclasses.
FTR, the size parameter of _io.RawIOBase.read is positional-only.
Since method's parameters of io.RawIOBase like _io.RawIOBase.read is positional-only, can we say that changing the parameters of io.RawIOBase to be the same as typing.IO would not cause compatibility break?
Activity
sobolevn commentedon Aug 24, 2023
Well, that's unfortunate :(
I don't think that we can change either of these two.
Because they both are a part of the contract.
kosta commentedon Aug 24, 2023
But isn't
RawIOBasesupposed to beIO[bytes]? At least that's how I understood it.I think a breaking change could be fine if it resolves a self-contradiction. In my opinion, the typing signature should be adjusted. But I am sure there are people with more knowledge on this subject than me ;)
erlend-aasland commentedon Aug 24, 2023
FTR, the size parameter of
_io.RawIOBase.readis positional-only.JelleZijlstra commentedon Aug 24, 2023
In typeshed we also mark this param positional-only: https://github.com/python/typeshed/blob/a094aa09c2aa47721664d3fdef91eda4fac24ebb/stdlib/typing.pyi#L720 (the double underscore means positional-only).
Maybe we should also make the runtime parameter positional-only. It's technically a compatibility break, but it's unlikely to affect a lot of people, and the parameter is positional-only on the most common practical IO types.
JelleZijlstra commentedon Aug 24, 2023
Child classes can have a broader parameter type than their parent class, so if you implement both
io.RawIOBaseandtyping.IO, it's OK to useint | Noneas the argument type even if one of the base classes only allowsint. Maybe we should have usedint | Noneintyping.IO, but changing this now is more likely to break existing subclasses.LoveEatCandy commentedon Jul 8, 2024
Since method's parameters of
io.RawIOBaselike_io.RawIOBase.readis positional-only, can we say that changing the parameters ofio.RawIOBaseto be the same astyping.IOwould not cause compatibility break?gh-108411: Make typing.IO/BinaryIO arguments positional-only (#142906)
SpecLad commentedon Apr 21, 2026
Looks like this should be closed, since it was completed by #142906.
pythongh-108411: Make typing.IO/BinaryIO arguments positional-only (p…