derwiki-adroll / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

mock module raises TypeError on being passed into builtin help function #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. import mock
2. help(mock)

What is the expected output? What do you see instead?

help should output something like:

NAME
    Mock

FILE
    /lib/python2.5/site-packages/...

MODULE DOCS
    ...

CLASSES

    ...

Instead the following exception is raised:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/stephen/lib/python/peopleproject/lib/python2.5/site.py", line
457, in __call__
    return pydoc.help(*args, **kwds)
  File "/usr/lib/python2.5/pydoc.py", line 1647, in __call__
    self.help(request)
  File "/usr/lib/python2.5/pydoc.py", line 1691, in help
    else: doc(request, 'Help on %s:')
  File "/usr/lib/python2.5/pydoc.py", line 1482, in doc
    pager(title % desc + '\n\n' + text.document(object, name))
  File "/usr/lib/python2.5/pydoc.py", line 324, in document
    if inspect.ismodule(object): return self.docmodule(*args)
  File "/usr/lib/python2.5/pydoc.py", line 1071, in docmodule
    inspect.getclasstree(classlist, 1), name)]
  File "/usr/lib/python2.5/inspect.py", line 656, in getclasstree
    for parent in c.__bases__:
TypeError: 'SentinelObject' object is not iterable

What version of the product are you using? On what operating system?

Mock 0.6.0/Python 2.5.4 running on Ubuntu linux.

Original issue reported on code.google.com by stephene...@gmail.com on 27 Aug 2009 at 9:29

GoogleCodeExporter commented 9 years ago
This may not be the only problem here, but Python uses inspect.getmembers method
during help(), which in turn calls hasattr(object, __bases__) to determine if 
the
Sentinal instance "sentinel" is a class.

from python hasattr docs:

This is implemented by calling getattr(object, name) and seeing whether it 
raises an
exception or not.

so forcing __getattr__ on Sentinel to raise an AttributeException for magic 
methods
prevents inspect from drilling into Sentinel with getclasstree, but is this 
defeating
the purpose of a Sentinel?

patch attached.

Original comment by stephene...@gmail.com on 28 Aug 2009 at 1:34

Attachments:

GoogleCodeExporter commented 9 years ago
Fixed in trunk. (Finally.) Not sure when I will do a new release though...

Original comment by fuzzyman on 3 Jan 2010 at 10:39

GoogleCodeExporter commented 9 years ago

Original comment by fuzzyman on 3 Jan 2010 at 10:39