[docs] [issue19154] AttributeError: 'NoneType' in http/client.py when using select when file descriptor is closed.

Terry J. Reedy report at bugs.python.org
Mon Oct 7 22:13:31 CEST 2013

Terry J. Reedy added the comment:

We are both talking about 2.7 httplib.HTTPResponse.fileno. I should have said that users should try: ...fileno(); except AttributeError rather than ValueError. Any caller can understand AttributeError as well as ValueError or any other exception.

It is not an error for a python function to raise an exception. In fact, it is the normal thing to do when it cannot do as requested. API changes are not allowed in 2.7 and this one would be dubious even in a future 3.x.

I do think the doc should be more informative and that

Return(s) the fileno of the underlying socket.

should be extended to indicate the specific exception raised when that is not possible.

Return the fileno of the underlying socket if there is one or raise AttributeError.

This should also be added as a docstring (currently missing).

The above is also true for 3.x as self.fp continues to be replaced with None on closing.

The HTTPResponse docs are known to be deficient. #3430

I do not think select needs to be changed to understand the HTTPResponse.fileno error indicator because it does not call that method. As indicated in the traceback, it calls (in 2.7) socket._fileinput.fileno. I believe it is only a bug in nappstore (that would be harder to reproduce in 3.x) that _fileinput.fileno is forwarded to HTTPResponse.fileno instead of _socket.fileno. The latter seem to be the clear intention. Even if I am wrong, changing something in the select or socket modules would be a different issue from changing something in the client module.

assignee:  -> docs at python
components: +Documentation -Library (Lib)
keywords: +easy, patch
nosy: +docs at python
stage: test needed -> needs patch
type: behavior -> enhancement
versions: +Python 3.3, Python 3.4

Python tracker <report at bugs.python.org>

More information about the docs mailing list