Skip to content

Commit

Permalink
Made todo for unaddressed global iterator name bug
Browse files Browse the repository at this point in the history
  • Loading branch information
atait committed Oct 13, 2020
1 parent 990c31d commit 15863ca
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/todo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ TODO List
.. todo:: Implement decorator to eliminate unused lines of code (assignments to unused values)
.. todo:: Technically, ``x += y`` doesn't have to be the same thing as ``x = x + y``. Handle it as its own operation of the form ``x += y; return x``
.. todo:: Support efficiently inlining simple functions, i.e. where there is no return or only one return as the last line of the function, using pure name substitution without loops, try/except, or anything else fancy
.. todo:: Catch replacement of loop variables that conflict with globals, or throw a more descriptive error when detected. See ``test_iteration_variable``

.. todolist::
27 changes: 27 additions & 0 deletions tests/test_collapse_literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,33 @@ def f2():
for a in range(3): # failure occurs when this is interpreted as "for 0 in range(3)"
x = a

def test_iteration_variable(self):
# global glbvar # TODO: Uncommenting should lead to a descriptive error
glbvar = 0

# glbvar in <locals> is recognized as in the __closure__ of f1
@pragma.collapse_literals
def f1():
x = glbvar
result = '''
def f1():
x = 0
'''
self.assertSourceEqual(f1, result)

# glbvar in <locals> is recognized as NOT in the __closure__ of f2
# but, if glbvar is in __globals__, it fails (and maybe should)
@pragma.collapse_literals
def f2():
for glbvar in range(3):
x = glbvar
result = '''
def f2():
for glbvar in range(3):
x = glbvar
'''
self.assertSourceEqual(f2, result)

def test_conditional_erasure(self):
@pragma.collapse_literals
def f(y):
Expand Down

0 comments on commit 15863ca

Please sign in to comment.