Title: Pydoc (and help) fails with socket.AddressFamily
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: barry, eli.bendersky, ethan.furman, pitrou, python-dev, serhiy.storchaka, vajrasky
Priority: normal Keywords: easy, patch

Created on 2014-02-17 07:25 by serhiy.storchaka, last changed 2014-02-19 21:07 by serhiy.storchaka. This issue is now closed.

File name Uploaded Description Edit
preliminary_patch_for_AF_UNSPEC_pydoc_error.diff vajrasky, 2014-02-17 09:02 review
pydoc_display_enum_member_value_0.patch vajrasky, 2014-02-17 14:16 review
pydoc_display_enum_member_value_0_v2.patch vajrasky, 2014-02-17 14:42 review
pydoc_display_enum_member_value_0_v3.patch vajrasky, 2014-02-18 02:40 review
Messages (11)
msg211395 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-17 07:25
$ ./python -m pydoc socket.AddressFamily
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/", line 171, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/serhiy/py/cpython/Lib/", line 86, in _run_code
    exec(code, run_globals)
  File "/home/serhiy/py/cpython/Lib/", line 2600, in <module>
  File "/home/serhiy/py/cpython/Lib/", line 2565, in cli
  File "/home/serhiy/py/cpython/Lib/", line 1847, in help
    elif request: doc(request, 'Help on %s:', output=self._output)
  File "/home/serhiy/py/cpython/Lib/", line 1585, in doc
    pager(render_doc(thing, title, forceload))
  File "/home/serhiy/py/cpython/Lib/", line 1578, in render_doc
    return title % desc + '\n\n' + renderer.document(object, name)
  File "/home/serhiy/py/cpython/Lib/", line 357, in document
    if inspect.isclass(object): return self.docclass(*args)
  File "/home/serhiy/py/cpython/Lib/", line 1284, in docclass
    lambda t: t[1] == 'data')
  File "/home/serhiy/py/cpython/Lib/", line 1248, in spilldata
    getattr(object, name, None) or homecls.__dict__[name],
KeyError: 'AF_UNSPEC'

But it works with other enum types: socket.SocketType, plistlib.PlistFormat, ssl.Purpose.
msg211400 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2014-02-17 09:02
This is the preliminary patch for this bug.

The bug happens because AddressFamily.AF_UNSPEC is 0. Then you have this if condition:
getattr(object, name, None) or homecls.__dict__[name]

I'll contemplate whether we should add unit test for this or not.
msg211401 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2014-02-17 09:03
I just realized that Enum member could be None. I'll think how to improve this patch.
msg211409 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-17 11:34
Just use getattr() without third argument and catch AttributeError.
msg211418 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2014-02-17 14:16
Here is the second preliminary patch. I'll think about the way to avoid dependency to socket module.
msg211419 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2014-02-17 14:42
Here is the second patch, avoiding dependency to socket.AddressFamily (though it adds dependency to enum library) in test.
msg211424 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-17 16:57
The fix itself looks good, but the test can be better. You write temporary file in current directory. this can fail for different reasons, Python can crash and left undeleted file, this file can overwrite existing file. The render_doc() function is last module level function in a traceback, and it can be used for testing, temporary file will be not needed.
msg211425 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-17 17:01
Interesting, that the documentation for AddressFamily (unlike to SocketType) isn't generated in html doc. May be this is unrelated issue, but if this is related, it would be good to fix it too. Otherwise it needs separate issue.
msg211471 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2014-02-18 02:40
Thanks for the review, Serhiy! Here is the patch addressing Serhiy's concern.
msg211655 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2014-02-19 21:05
New changeset 8a3e896f0681 by Serhiy Storchaka in branch 'default':
Issue #20654: Fixed pydoc for enums with zero value.  Patch by Vajrasky Kok.
msg211656 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-02-19 21:07
Thank you Vajrasky!
Date User Action Args
2014-02-19 21:07:21serhiy.storchakasetstatus: open -> closed
type: behavior
messages: + msg211656

resolution: fixed
stage: needs patch -> resolved
2014-02-19 21:05:33python-devsetnosy: + python-dev
messages: + msg211655
2014-02-18 02:40:32vajraskysetfiles: + pydoc_display_enum_member_value_0_v3.patch

messages: + msg211471
2014-02-17 17:01:05serhiy.storchakasetmessages: + msg211425
2014-02-17 16:57:29serhiy.storchakasetmessages: + msg211424
2014-02-17 14:42:10vajraskysetfiles: + pydoc_display_enum_member_value_0_v2.patch

messages: + msg211419
2014-02-17 14:16:57vajraskysetfiles: + pydoc_display_enum_member_value_0.patch

messages: + msg211418
2014-02-17 11:34:34serhiy.storchakasetkeywords: + easy
assignee: serhiy.storchaka
stage: needs patch
2014-02-17 11:34:11serhiy.storchakasetmessages: + msg211409
2014-02-17 09:03:38vajraskysetmessages: + msg211401
2014-02-17 09:02:40vajraskysetfiles: + preliminary_patch_for_AF_UNSPEC_pydoc_error.diff

nosy: + vajrasky
messages: + msg211400

keywords: + patch
2014-02-17 07:25:53serhiy.storchakacreate