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
I can make a Pull Request if introducing the inheritance (and removing redundant attributes/methods) is all that is needed, but I am very unsure if that's it, so I decided to open this issue before anything else.
Changes to the IO class hierarchy tend to be tricky, because the IO protocols are inconsistent and there are sometimes incompatible method overrides. In this case, BytesIO already inherits from BinaryIO, so there's a risk that making it also inherit from BufferedIOBase will cause trouble.
I see. I find it fairly unexpected that mypy ends up with an error that directly contradicts the definition of BytesIO in the standard library, and its documentation as well (the documentation explicitly says that it inherits BufferedIOBase). But I see how this definition can be fairly tricky, especially after reading some other issues here.
I ended up depending on BinaryIO where I could, and where I used isinstance checks I ended up settling for hasattr(obj, "read") or similar. Serves my purpose right now.
Feel free to close this if desired (or maybe keep as an issue version of the TODO?).
Just to be clear I don't know for sure what will happen if we make BytesIO inherit from BufferedIOBase; feel free to submit a PR and see what Travis has to say. I just wanted to give some explanation for why this might turn out to be tricky. I do agree that this should be fixed.
Activity
JelleZijlstra commentedon May 25, 2020
Changes to the IO class hierarchy tend to be tricky, because the IO protocols are inconsistent and there are sometimes incompatible method overrides. In this case,
BytesIOalready inherits fromBinaryIO, so there's a risk that making it also inherit fromBufferedIOBasewill cause trouble.tarcisioe commentedon May 25, 2020
I see. I find it fairly unexpected that
mypyends up with an error that directly contradicts the definition ofBytesIOin the standard library, and its documentation as well (the documentation explicitly says that it inheritsBufferedIOBase). But I see how this definition can be fairly tricky, especially after reading some other issues here.I ended up depending on
BinaryIOwhere I could, and where I usedisinstancechecks I ended up settling forhasattr(obj, "read")or similar. Serves my purpose right now.Feel free to close this if desired (or maybe keep as an issue version of the TODO?).
JelleZijlstra commentedon May 25, 2020
Just to be clear I don't know for sure what will happen if we make BytesIO inherit from BufferedIOBase; feel free to submit a PR and see what Travis has to say. I just wanted to give some explanation for why this might turn out to be tricky. I do agree that this should be fixed.