Conversation
Started out as progress towards python#1476, but I ended up fixing a few more things: - fixed the signature of _encode_type, which actually returns a pair, not a string - made some attributes into properties in order to prevent the descriptor protocol from turning them into methods - found a bug in CPython in the process (python/cpython#6779) I used the following test file to make sure these classes are now instantiable: ```python import codecs import io from typing import IO bio = io.BytesIO() cod = codecs.lookup('utf-8') codecs.StreamReaderWriter(bio, codecs.StreamReader, codecs.StreamWriter) codecs.StreamRecoder(bio, cod.encode, cod.decode, codecs.StreamReader, codecs.StreamWriter) ```
gvanrossum
left a comment
There was a problem hiding this comment.
I would understand if you don't want to keep tweaking this PR so I'm approving it at the same time as suggesting some extra work. Up to you!
| @@ -33,8 +34,8 @@ _encoded = bytes | |||
|
|
|||
There was a problem hiding this comment.
It's really too bad that this file uses all-lowercase names to indicate various type aliases. But maybe now's not the right time to fix that.
| @@ -2,6 +2,7 @@ | |||
| # https://docs.python.org/2/library/codecs.html and https://docs.python.org/3/library/codecs.html | |||
There was a problem hiding this comment.
Honestly the attribution comment does not belong here, nor does the value judgment.
| def __exit__(self, typ: Optional[Type[BaseException]], exc: Optional[BaseException], tb: Optional[types.TracebackType]) -> bool: ... | ||
| def __getattr__(self, name: str) -> Any: ... | ||
|
|
||
| # These methods don't actually exist directly, but they are needed to satisfy the TextIO |
There was a problem hiding this comment.
Is there no way to introduce these through inheritance?
There was a problem hiding this comment.
They're abstract on the base classes, so we need to have them here to make these classes non-abstract. Maybe there's some class in io that we could inherit from, but that wouldn't be accurate either since this class doesn't inherit from those classes at runtime.
There was a problem hiding this comment.
OK, let's keep this (verbose) approach then.
Started out as progress towards python#1476, but I ended up fixing a few more things: - fixed the signature of _encode_type, which actually returns a pair, not a string - made some attributes into properties in order to prevent the descriptor protocol from turning them into methods - found a bug in CPython in the process (python/cpython#6779) I used the following test file to make sure these classes are now instantiable: ```python import codecs import io from typing import IO bio = io.BytesIO() cod = codecs.lookup('utf-8') codecs.StreamReaderWriter(bio, codecs.StreamReader, codecs.StreamWriter) codecs.StreamRecoder(bio, cod.encode, cod.decode, codecs.StreamReader, codecs.StreamWriter) ```
Started out as progress towards #1476, but I ended up fixing a few more things:
I used the following test file to make sure these classes are now instantiable: