Ticket #3455 defect closed fixed
CONNECTION_LOST not an Integer...
| Reported by: | mforbes | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | core | Keywords: | documentation |
| Cc: | thijs | Branch: | branches/writesomedata-docs-3455 |
| Author: | exarkun | Launchpad Bug: |
Description
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
