Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pydoc requires o.__nonzero__() == True #41945

Closed
jaytmiller mannequin opened this issue May 3, 2005 · 3 comments
Closed

pydoc requires o.__nonzero__() == True #41945

jaytmiller mannequin opened this issue May 3, 2005 · 3 comments
Labels
stdlib Python modules in the Lib dir

Comments

@jaytmiller
Copy link
Mannequin

jaytmiller mannequin commented May 3, 2005

BPO 1194449
Nosy @birkenfeld
Files
  • pydoc_nonzero.patch: Patch to relax requirements on o.nonzero()
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2007-03-13.22:17:06.000>
    created_at = <Date 2005-05-03.13:18:26.000>
    labels = ['library']
    title = 'pydoc requires o.__nonzero__() == True'
    updated_at = <Date 2007-03-13.22:17:06.000>
    user = 'https://bugs.python.org/jaytmiller'

    bugs.python.org fields:

    activity = <Date 2007-03-13.22:17:06.000>
    actor = 'georg.brandl'
    assignee = 'ping'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2005-05-03.13:18:26.000>
    creator = 'jaytmiller'
    dependencies = []
    files = ['6640']
    hgrepos = []
    issue_num = 1194449
    keywords = ['patch']
    message_count = 3.0
    messages = ['48289', '48290', '48291']
    nosy_count = 3.0
    nosy_names = ['ping', 'georg.brandl', 'jaytmiller']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1194449'
    versions = ['Python 2.4']

    @jaytmiller
    Copy link
    Mannequin Author

    jaytmiller mannequin commented May 3, 2005

    On Tue, 2005-05-03 at 07:44, Nadav Horesh wrote:
    >>> import numarray as N
    > >>> a = N.array((2.3, 4.3))
    > >>> N.__version__
    > '1.3.1'
    > >>> help(a.stddev)
    > 
    > Traceback (most recent call last):
    >   File "<pyshell#11>", line 1, in -toplevel-
    >     help(a.stddev)
    >   File "/usr/local/lib/python2.4/site.py", line 328,
    in __call__
    >     return pydoc.help(*args, **kwds)
    >   File "/usr/local/lib/python2.4/pydoc.py", line
    1647, in __call__
    >     self.help(request)
    >   File "/usr/local/lib/python2.4/pydoc.py", line
    1691, in help
    >     else: doc(request, 'Help on %s:')
    >   File "/usr/local/lib/python2.4/pydoc.py", line
    1475, in doc
    >     pager(title % desc + '\n\n' +
    text.document(object, name))
    >   File "/usr/local/lib/python2.4/pydoc.py", line 297,
    in document
    >     if inspect.isroutine(object): return
    self.docroutine(*args)
    >   File "/usr/local/lib/python2.4/pydoc.py", line
    1226, in docroutine
    >     if object.im_self:
    >   File
    "/usr/local/lib/python2.4/site-packages/numarray/generic.py",
    > line 537, in __nonzero__
    >     raise RuntimeError("An array doesn't make sense
    as a truth value. 
    > Use any(a) or all(a).")
    > RuntimeError: An array doesn't make sense as a truth
    value.  Use any(a)
    > or all(a).
    > >>> help(a.sum)
    > 
    > 
    In my opinion,  this is a limitation (bug is maybe too
    strong) of pydoc,  in that pydoc's docroutine method
    requires that an object be evaluable as a truth value
    and that the result be True.   I think that's a common,
    but wrong, idiom.

    I believe it's widely recognized that array's don't
    make much sense as truth values because it leads to
    code like this:

    >>> a = array(5);  b = array(8)
    >>> a & b
    array(0)
    >>> if a & b:
    ...    print "foo!"
    foo!

    Numeric expressions like the above implicitly mean
    any(a & b) and appear to work but really contain subtle
    bugs.

    Hence, in numarray and Numeric3 (now or eventually),
    the exception:

    >>> if a & b:
    ... 	print "foo!"
    ... 
    Traceback (most recent call last):
    ...
    RuntimeError: An array doesn't make sense as a truth
    value.  Use any(a) or all(a).

    I think the pydoc docroutine() code should be changed
    to read:

    if object.im_self is not None:

    and that particular limitation will be removed. I
    submitted a patch.

    Regards,
    Todd

    @jaytmiller jaytmiller mannequin closed this as completed May 3, 2005
    @jaytmiller jaytmiller mannequin closed this as completed May 3, 2005
    @jaytmiller jaytmiller mannequin assigned ping May 3, 2005
    @jaytmiller jaytmiller mannequin added stdlib Python modules in the Lib dir labels May 3, 2005
    @jaytmiller
    Copy link
    Mannequin Author

    jaytmiller mannequin commented May 3, 2005

    Logged In: YES
    user_id=320512

    The attached patch fixed my immediate problem but is
    untested against the Python test suites. I did not do a
    careful analysis for other uses of the "if o:" idiom but
    noted that there are many of which I'm fixing two. I only
    have anonymous access to Python CVS and it is unusable.

    @birkenfeld
    Copy link
    Member

    Thanks for the patch, fixed in rev. 54365, 54366 (2.5).

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant