Hi. Here are some things i noticed tonight. 1. The error message for UnboundLocalError isn't really accurate. >>> def f(): ... x = 1 ... del x ... print x ... >>> f() Traceback (most recent call last): File "<stdin>", line 1, in ? File "<stdin>", line 4, in f UnboundLocalError: local variable 'x' referenced before assignment >>> It's not a question of the variable being referenced "before assignment" -- it's just that the variable is undefined. Better would be a straightforward message such as UnboundLocalError: local name 'x' is not defined This message would be consistent with the others: NameError: name 'x' is not defined NameError: global name 'x' is not defined 2. Why does imp.find_module('') succeed? >>> import imp >>> imp.find_module('') (None, '/home/ping/python/', ('', '', 5)) I think it should fail with "empty module name" or something similar. 3. Normally when a script is run, it looks like '' gets prepended to sys.path so that the current directory will be searched. But if the script being run is a symlink, the symlink is resolved first to an actual file, and the directory containing that file is prepended to sys.path. This leads to strange behaviour: localhost[1004]% cat > spam.py bacon = 5 localhost[1005]% cat > /tmp/eggs.py import spam localhost[1006]% ln -s /tmp/eggs.py . localhost[1007]% python eggs.py Traceback (most recent call last): File "eggs.py", line 1, in ? import spam ImportError: No module named spam localhost[1008]% python Python 2.1a2 (#23, Feb 11 2001, 16:26:17) [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 Type "copyright", "credits" or "license" for more information. >>> import spam >>> (whereupon the confused programmer says, "Huh? If *i* could import spam, why couldn't eggs?"). Was this a design decision? Should it be changed to always prepend ''? 4. As far as i can tell, the curses.wrapper package is inaccessible. It's obscured by a curses.wrapper() function in the curses package. >>> import curses.wrapper >>> curses.wrapper <function wrapper at 0x80ebe14> >>> import sys >>> sys.modules['curses.wrapper'] <module 'curses.wrapper' from '/home/ping/dev/python/dist/src/Lib/curses/wrapper.pyc'> I don't see any way around this other than renaming curses.wrapper. -- ?!ng "If I have not seen as far as others, it is because giants were standing on my shoulders." -- Hal Abelson
On Tue, Feb 27, 2001 at 03:53:08AM -0800, Ka-Ping Yee wrote:
4. As far as i can tell, the curses.wrapper package is inaccessible. It's obscured by a curses.wrapper() function in the curses package.
The function in the packages results from 'from curses.wrapper import wrapper', so there's really no need to import curses.wrapper directly. Hmmm... but the module is documented in the library reference. I could move the definition of wrapper() into the __init__.py and change the docs, if that's desired. --amk
Hi again. On Tue, 27 Feb 2001, Ka-Ping Yee wrote:
1. The error message for UnboundLocalError isn't really accurate.
[...]
UnboundLocalError: local name 'x' is not defined
I'd like to check in this change today to make it into the beta. It's a tiny change, shouldn't break anything as i don't see how code would rely on the wording of the message, and makes the message more accurate. Lib/test/test_scope.py checks for the error but does not rely on its wording. If i don't see objections i'll do this tonight. I hope this is minor enough not to be a violation of etiquette. -- ?!ng
[Ka-Ping Yee]
On Tue, 27 Feb 2001, Ka-Ping Yee wrote:
1. The error message for UnboundLocalError isn't really accurate.
[...]
UnboundLocalError: local name 'x' is not defined
I'd like to check in this change today to make it into the beta. It's a tiny change, shouldn't break anything as i don't see how code would rely on the wording of the message, and makes the message more accurate. Lib/test/test_scope.py checks for the error but does not rely on its wording.
If i don't see objections i'll do this tonight. I hope this is minor enough not to be a violation of etiquette.
Sorry, but I really didn't like this change. You had to contrive a test case using "del" for the old local variable 'x' referenced before assignment msg to appear inaccurate the way you read it. The old msg is much more on-target 99.999% of the time than just saying "not defined", in non-contrived test cases. Even in the "del" case, it's *still* the case that the vrbl was referenced before assignment (but after "del"). So -1, on the grounds that the new msg is worse (because less specific) almost all the time.
Based on Tim's comment I change my +1 into a -1. I had forgotten the context. --Guido van Rossum (home page: http://www.python.org/~guido/)
On Tue, 27 Feb 2001, Ka-Ping Yee wrote:
1. The error message for UnboundLocalError isn't really accurate.
[...]
UnboundLocalError: local name 'x' is not defined
I'd like to check in this change today to make it into the beta. It's a tiny change, shouldn't break anything as i don't see how code would rely on the wording of the message, and makes the message more accurate. Lib/test/test_scope.py checks for the error but does not rely on its wording.
If i don't see objections i'll do this tonight. I hope this is minor enough not to be a violation of etiquette.
+1, but first address the comments about test_inspect.py with -O. --Guido van Rossum (home page: http://www.python.org/~guido/)
participants (5)
-
Andrew Kuchling
-
Guido van Rossum
-
Ka-Ping Yee
-
Neil Schemenauer
-
Tim Peters