-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
improve io #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
improve io #194
Conversation
0b342d0
to
a7f9e30
Compare
@@ -80,6 +80,7 @@ class _ListDataStream(io.BufferedIOBase): | |||
def __init__(self, lst) -> None: ... | |||
def writable(self) -> bool: ... | |||
def seekable(self) -> bool: ... | |||
@no_type_check # not same signature as parent | |||
def write(self, b: str) -> None: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend using # type: ignore
here instead of @no_type_check
. The latter means that the annotations aren't even in mypy's language; the former just suppresses the complaint about the type mismatch.
Though maybe there's a different solution possible altogether? Having to suppress this smells a bit...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT from some experimentation, write() actually takes bytes too. But since this is an internal class used only by tostringlist() maybe it's better to get rid of it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT from some experimentation, write() actually takes bytes too. But since this is an internal class used only by tostringlist() maybe it's better to get rid of it?
Removed then.
There certainly is -- use checks for IIRC it's just a historical accident that the xml.etree stubs were repeated (maybe at the time we wanted them to be version-precise despite mypy not implementing version checks yet, but personally I don't think that's important). |
22d26b2
to
c253a77
Compare
Travis gives me
for if sys.version_info >= (3, 3):
BlockingIOError = BlockingIOError
class UnsupportedOperation(OSError, ValueError): ...
else:
class BlockingIOError(IOError):
characters_written = ... # type: int
class UnsupportedOperation(IOError, ValueError): ... I guess it is a mypy issue, because any path would only declare these once, should I report it? For now, even if it is somewhat wrong, we can keep the |
SEEK_SET = ... # type: int | ||
SEEK_CUR = ... # type: int | ||
SEEK_END = ... # type: int | ||
if sys.version_info >= (3, 1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mypy doesn't support Python 3.0 or 3.1, so you can put this block in unconditionally.
Yeah, there are several mypy issue still open related to conditional definitions. Anyway, please get rid of the 3.1 version checks; the rest looks good so far. |
Done. It's somewhat more readable now. |
There are so many changes here, this feel risky, but I'm going to risk it. We'll see if someone reports problems. |
Sadly this breaks some mypy tests: https://travis-ci.org/python/mypy/jobs/129495880
Please see what you can do about this... |
add some type checking to io and _io.
I've moved everything needed from
_io
toio
as it was public anyway.I've had to fix lxml as it was not using the same signature as the parent
I decided to add a
@no_type_check
, but it may not be the best way.Also, there seems to be some small differences between some python version (
__del__
forIOBase
in python3.5,BlockingIOError
which goes fromio
tobuiltin
, ...), is there a way to avoid coping the nearly identical module everywhere?