[Python-bugs-list] [ python-Bugs-449493 ] <module>.__dict__ goes into 'help>'

noreply@sourceforge.net noreply@sourceforge.net
Thu, 09 Aug 2001 07:25:20 -0700


Bugs item #449493, was opened at 2001-08-09 07:11
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=449493&group_id=5470

>Category: Python Library
>Group: 3rd Party
>Status: Closed
>Resolution: Works For Me
Priority: 5
Submitted By: Mario Ruggier (ruggier)
Assigned to: Nobody/Anonymous (nobody)
Summary: <module>.__dict__ goes into 'help>'

Initial Comment:
Environment: 
ActiveState Python21 (#15, April 16 2001) on Win2000.

Problem:
when I ask for the __dict__ of a module interactively,
I am consistently presneted with python interactive 
elp prompt. The __dict__ seems to be returned 
orrectly, but for the 'help' entry (the last shown), 
it prints some about-help info, and then presents the 
help prompt. This seems to happen with any module, 
even standard modules such as 're'. 

==
Additional remarks (to post on python-help)
from Alex Martelli:

I don't have that particular build installed, so I 
don't observe this phenomenon (I don't even get 
'help' entry in my modules!-) -- but it's easy to see 
what must be happening.

When you type an expression-statement at the 
interactive interpreter prompt, and that expression 
returns a result that is not None, the interactive 
interpreter's default hook (sys.displayhook) emits the 
repr() of that result (and also sets __builtin__._ to 
the result).  The repr() of a dictionary, in turn, 
calls the repr() of each key and value of that 
dictionary (as well as emitting some other stuff).

So, given the symptoms you observe, it must be that 
the whatever.__dict__['help'] entry is set to an 
object such that its repr() 'presents a prompt' (at 
least when called from an interactive session -- 
isatty (stdout) or something like that).  This is 
presumably done so that one can just write at the 
interpreter prompt
    >>> re.help
(etc) and get the interactive-session implicitly, 
rather than having to bother with a CALL of it
    >>> re.help()
as would presumably be more natural.

I can see how this could be a bother -- things meant
to be highly convenient under certain hypotheses can
easily be a bother instead of those hypotheses do not
obtain!  One fix might be to tweak the sys.displayhook
for your purposes: if it's passed specifically a
dictionary, it could display, instead of the repr
of that dictionary, the repr of a slightly different
dictionary whose 'help' key's value, if any, is
temporarily changed to a non-highly-magical object.
Just for example...

It might be worth posting this as a bug to the
bug-tracker at python.sourceforge.net -- if you
do so, please feel free to include any or all
of this response.

Alex




----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-08-09 07:25

Message:
Logged In: YES 
user_id=6380

It appears that ActiveState have added the help feature more
aggressively to their release than PythonLabs.  The
PythonLabs releases through 2.1.1 do not include help among
the built-ins.  In Python 2.2a1, help is a builtin, but
asking for its repr() does not enter interactive help mode
-- you have to type help() for that. I'll forward this bug
report to ActiveState.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=449493&group_id=5470