Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to report a bug with Python's 'help()' function?
    text
    copied!<p>As a hobby/learning project, I'm writing a parser generator in Python. One of my code files is named "token.py" - which contains a couple of classes for turning plain strings into Token objects. I've just discovered that using the "help()" function from the console in Python raises an error for any module defined in a directory that contains a "token.py". </p> <p>Here's a way to reproduce the error. Create a new directory with the following files:</p> <pre><code>/New Folder main.py token.py </code></pre> <p>Leave 'token.py' blank. In main.py, write a simple function - for example:</p> <pre><code>def test(): pass </code></pre> <p>Then, in your Python console, import 'main' and call 'help(main.test)' - here's what you'll get:</p> <pre><code>C:\New Folder&gt;python Python 3.1.1 (r311:74483, Aug 17 2009, 17:02:12) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; import main &gt;&gt;&gt; help(main.test) Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "C:\Python31\lib\site.py", line 428, in __call__ import pydoc File "C:\Python31\lib\pydoc.py", line 55, in &lt;module&gt; import sys, imp, os, re, inspect, builtins, pkgutil File "C:\Python31\lib\inspect.py", line 40, in &lt;module&gt; import tokenize File "C:\Python31\lib\tokenize.py", line 37, in &lt;module&gt; COMMENT = N_TOKENS NameError: name 'N_TOKENS' is not defined &gt;&gt;&gt; </code></pre> <p>If you delete the 'token.py' file, help() will behave normally. Both Python 3.1 and Python 2.5 exhibit this behavior.</p> <p>Is this a known issue? If not, how do I report it?</p> <p>EDIT:</p> <p>Several comments state that this behavior isn't a bug. The module that defines "help" imports a module called "token" from Python's standard library. However, Python looks in the application folder before it looks in its library to find modules. In the example above, "help" tries to use my "token.py" instead of Python's, which causes the error.</p> <p>Since Python is defined to exhibit this behavior, I suppose it isn't a bug. But why do people think that this behavior is acceptable? It implies that adding new modules to Python's library - even without changing existing modules - could break existing applications. It also implies that programmers are expected to have memorized the names of all modules in Python's library - how is that any less ridiculous than expecting programmers to memorize every namespace in .NET or Java? Why don't Python applications get their own namespaces? Why aren't Python standard library modules in their own namespace?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload