[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Python 2.1 out



At some point, D-Man <dsh8290@rit.edu> wrote:

> On Thu, Apr 19, 2001 at 12:17:40PM +0200, Florian Weimer wrote:
> | Gregor Hoffleit <gregor@mediasupervision.de> writes:
> | 
> | [Python warning messages]
> | 
> | > Could you mail an example of such a message ?
> | 
> | y = None
> | def fun():
> |     y = None
> |     def bar():
> |         y
> |     bar()
> | 
> | fun()
> | 
> | results in:
> | 
> | <file>:2: SyntaxWarning: local name 'y' in 'fun' shadows use of 'y' as global in nested scope 'bar'
> |   def fun():
> 
> Yeah, that code will almost certainly break in 2.2 when nested scopes
> become mandatory.  It may have been intended, but assignment to a
> local variable overshadowing a global is rarely the intended effect.
> 

Just to make it clearer -- the warning is *not* because of the global
y. The minimalist version is

def fun():
    y = None
    def bar():
        y

<file>:1: SyntaxWarning: local name 'y' in 'fun' shadows use of 'y' as global in nested scope 'bar'

Also, it's a syntax warning, so it's caught at compile time -- any
scripts where this occurs will be caught before they run, making it
trivial to figure out where the problems are.

> Anyways, if you want to get rid of those message now, without changing
> the code use the  -W option to the interpreter.  Example :
> 
> $ python -W ignore Scope.py
> 
> (I created a file called Scope.py with that code in it)
> 

A quick examination of the package lists show ~39 'python-*' packages
that don't have equivalent 'python2-*' packages. There are about ~100
packages that depend on python-base that would have to be checked for
compatibility with Python 2.1.

I think it's safe to say that wholesale use of 'python -W ignore'
would be unwarranted, because a lot of other stuff has to checked
any way ;-)

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke
|cookedm@mcmaster.ca



Reply to: