#4 No global bug?

closed
nobody
None
5
2014-08-14
2002-11-27
No

I have two files:

------------------------------------------------
runner.py:

#! /usr/bin/env python

import pychecker.checker
from my_module import mangle_hash

hash = {'A':range(5),
'B': range(10, 15),
'C':range(20, 25)}
mangle_hash(hash)
------------------------------------------------
my_module.py:

def mangle_hash (my_hash):
new_hash = {}
for key in my_hash.keys():
new_hash[squidy] = my_hash[key]
print new_hash
------------------------------------------------

When I run runner.py, I get this output:

my_module.py:4: No global (squidy) found
{'squidy': [10, 11, 12, 13, 14]}

Indicating that the previously undeclared variable
squidy is being converted to the string 'squidy', which
is then used as a key for new_hash.

When I run runner without importing pychecker.checker,
I get the expected error:

Traceback (most recent call last):
File "./runner.py", line 9, in ?
mangle_hash(hash)
File "./my_module.py", line 4, in mangle_hash
new_hash[squidy] = my_hash[key]
NameError: global name 'squidy' is not defined

This makes me think that when pychecker finds the
non-existant variable squidy, it is making it into a
string.

Is this a bug? To me, this behavior is unexpected,
because it converts an mistake that normally causes an
exception into a pychecker warning. I didn't see
anyway to directly turn this behaviour off in pycheckrc.

Thank you,

Josh

Discussion

  • Neal Norwitz

    Neal Norwitz - 2002-12-12

    Logged In: YES
    user_id=33168

    Depending on how you look at this it's a bug or a feature. :-)
    pychecker does some dirty things to globals, so you don't
    get the exception.
    You can disable this feature by using the -g/--allglobals' flag.
    When run with this flag:

    [neal@epoch pychecker]$ PYCHECKER='--allglobals' python s1.py
    s2.py:6: No global (squidy) found
    Traceback (most recent call last):
    File "s1.py", line 8, in ?
    mangle_hash(hash)
    File "s2.py", line 6, in mangle_hash
    new_hash[squidy] = my_hash[key]
    NameError: global name 'squidy' is not defined

     
  • Neal Norwitz

    Neal Norwitz - 2003-11-17
    • status: open --> closed
     
  • Neal Norwitz

    Neal Norwitz - 2003-11-17

    Logged In: YES
    user_id=33168

    Closed due to no activity. Let me know if you still have
    problems.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks