CONNECTION_LOST not an Integer...
|Reported by:||mforbes||Owned by:|
branch-diff, diff-cov, branch-cov, buildbot
Several docstrings, notably those for the writeSomeData() method of t.i.a.FileDescriptor, claim that the return value is an integer reporting the number of bytes sent, or a negative integer reporting that the connection was lost.
The implementations, however, return t.i.main.CONNECTION_LOST which is an exception, not an integer.
Apart from the incorrect docstrings, returning an exception makes it quite difficult to test for errors. For example:
bytes_sent = self.connection.writeSomeData(...) if 0 < bytes_sent: Still get here, even if connection is lost.
One has to check if the return value is explicitly CONNECTION_LOST, or if it is an instance of int etc.
Suggestion: Have writeSomeData throw the exception, or revert back to using an integer...
A quick grep indicates that this would require changes in the following files.
./Twisted/twisted/internet/_javaserialport.py ./Twisted/twisted/internet/_posixserialport.py ./Twisted/twisted/internet/abstract.py ./Twisted/twisted/internet/fdesc.py ./Twisted/twisted/internet/process.py ./Twisted/twisted/internet/tcp.py ./Twisted/twisted/protocols/htb.py ./Twisted/twisted/protocols/pcp.py ./Twisted/twisted/test/test_internet.py ./Twisted/twisted/test/test_pcp.py
Change History (8)
comment:1 Changed 8 years ago by therve
- Keywords documentation added; CONNECTION_LOST writeSomeData removed
comment:3 Changed 8 years ago by exarkun
- Owner changed from glyph to exarkun
- Status changed from new to assigned
comment:5 Changed 8 years ago by exarkun
- Keywords review added
- Owner exarkun deleted
- Status changed from assigned to new