Title: Help well execute code it is called on
Type: behavior Stage:
Components: Documentation Versions:
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: ezio.melotti, georg.brandl, imiers1
Priority: normal Keywords:

Created on 2009-05-30 06:37 by imiers1, last changed 2009-05-30 07:17 by georg.brandl. This issue is now closed.

File name Uploaded Description Edit imiers1, 2009-05-30 06:37 an example of the bug
Messages (3)
msg88565 - (view) Author: Ian Miers (imiers1) Date: 2009-05-30 06:37
when calling help() from the python interpreter on a function 
whose default argument is provided by another function 
( e.g. def foo(bar=baz() ) : .... ), help will call baz().

This can cause problems because baz() can alter statefull
data  like a file or database entry. 

This is both a bug in that it does this and in that
its undocumented 

To see this download the attached file and then : 
Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bug
>>> help(bug)

at this point the file bug now has been written to disk. 
This is a problem

I've got to think there is a reason for this, but seeing as I cant 
come up with it , better safe than sorry.
msg88566 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-05-30 06:55
Default args are evaluated when the module is imported, if the arg is a
function call, the function is called.
You can see how the file is created just after the import, you don't
even need to call help().

This behavior is documented here:

The doc doesn't mention explicitly function calls, that could be added.
msg88567 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-05-30 07:17
Ezio is correct.  The file is already created while importing bug, not
due to the call to help().
Date User Action Args
2009-05-30 07:17:11georg.brandlsetstatus: open -> closed
resolution: not a bug
messages: + msg88567
2009-05-30 06:55:22ezio.melottisetversions: - Python 2.6, Python 2.5
nosy: + ezio.melotti

messages: + msg88566

components: - Interpreter Core
2009-05-30 06:37:19imiers1create