Author luke.schubert
Recipients luke.schubert
Date 2016-02-01.09:57:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1454320625.23.0.218294172463.issue26255@psf.upfronthosting.co.za>
In-reply-to
Content
If the following function is saved in listcomp.py:

def encode(inputLetters):
    code = {'C':'D', 'F':'E'}
    return set(code[x] for x in inputLetters)

and the following code is used to create a symtable for this function:

import symtable

if __name__ == "__main__":
    fileName = 'listcomp.py'
    f = open(fileName, 'r')
    source = f.read()
    table = symtable.symtable(source, fileName, 'exec')
    children = table.get_children()
    for childTable in children:
        symbols = childTable.get_symbols()
        for s in symbols:
            if (not s.is_referenced()):
                print ("Unused symbol '%s' in function '%s'"
                       % (s.get_name(), childTable.get_name()))

then is_referenced() returns false for the 'code' symbol.

If the following function is saved instead:

def encode2(inputLetters):
    code = {'C':'D', 'F':'E'}
    return [ code[x] for x in inputLetters ]

then is_referenced() returns true for the 'code' symbol.

Possibly I'm misunderstanding what is_referenced() means, but I thought it should return true in both cases?
History
Date User Action Args
2016-02-01 09:57:05luke.schubertsetrecipients: + luke.schubert
2016-02-01 09:57:05luke.schubertsetmessageid: <1454320625.23.0.218294172463.issue26255@psf.upfronthosting.co.za>
2016-02-01 09:57:05luke.schubertlinkissue26255 messages
2016-02-01 09:57:04luke.schubertcreate