Python中调用help(help)时'with a twist'是什么意思?

What does 'with a twist' mean when help(help) is called in Python?

help(help)这是 pydoc.help 的包装(有一个扭曲)。

扭曲是什么?

$ python 
Python 2.7.10 (default, Jul 30 2016, 19:40:32) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> help(help)
Help on _Helper in module site object:

class _Helper(__builtin__.object)
 |  Define the builtin 'help'.
 |  This is a wrapper around pydoc.help (with a twist).
 |  
 |  Methods defined here:
 |  
 |  __call__(self, *args, **kwds)
 |  
 |  __repr__(self)
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)

没有太大的转折。不同之处在于 pydoc 延迟 导入的,并且该对象有一个 __repr__ 方法可以提供有关如何使用该对象的直接反馈:

>>> repr(help)
'Type help() for interactive help, or help(object) for help about object.'

只要您在交互式提示中回显 help 对象,就会调用 __repr__ 方法:

>>> help
Type help() for interactive help, or help(object) for help about object.

Python 3.4 完全去掉了 'twist' 描述,取而代之的是更具描述性的内容;参见 issue 9364。引用漏洞报告者的话:

"(with a twist)" thanks a lot. I think the comment should be either removed or explained. A reference manual should explain, not tease.

后面是开发者的回复:

Agreed. I think the “twist” is that the import is lazy and that help has a useful repr (wow, talk about a twist!). Those details need not be alluded to, just remove the comment (“wrapper” is IMO enough to raise curiosity, the source is here to find what’s the wrapping).

文档字符串现在显示为:

class _Helper(object):
    """Define the builtin 'help'.

    This is a wrapper around pydoc.help that provides a helpful message
    when 'help' is typed at the Python interactive prompt.

    Calling help() at the Python prompt starts an interactive help session.
    Calling help(thing) prints help for the python object 'thing'.
    """