[issue26255] symtable.Symbol.is_referenced() returns false for valid use

2016-02-01 Thread Luke Schubert

New submission from Luke Schubert:

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?

--
messages: 259316
nosy: luke.schubert
priority: normal
severity: normal
status: open
title: symtable.Symbol.is_referenced() returns false for valid use
versions: Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26255] symtable.Symbol.is_referenced() returns false for valid use

2016-02-01 Thread SilentGhost

Changes by SilentGhost :


--
components: +Extension Modules, Library (Lib)
nosy: +benjamin.peterson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26255] symtable.Symbol.is_referenced() returns false for valid use

2016-02-01 Thread Xiang Zhang

Changes by Xiang Zhang <18518281...@126.com>:


--
nosy: +xiang.zhang

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue26255] symtable.Symbol.is_referenced() returns false for valid use

2016-02-01 Thread Benjamin Peterson

Benjamin Peterson added the comment:

The genexp implicitly creates a nested function in which *code* is referenced.

--
resolution:  -> not a bug
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com