Ticket #208 (closed defect: fixed)

Opened 4 years ago

Last modified 4 years ago

empty for-int-in-range loop doesn't behave as in Python

Reported by: scoder Owned by: robertwb
Priority: minor Milestone: 0.11.1
Component: Python Semantics Keywords:
Cc:

Description

When optimised into a C loop, the for-in-range loop over an empty range still changes the value of the loop variable. In Python, this is not the case.

def go_py_empty():
    i = 20
    for i in range(4,0):
        print u"Spam!"
    return i # == 20

def go_c_empty():
    cdef int i = 20
    for i in range(4,0):
        print u"Spam!"
    return i # == 3

Attachments

if_patch.txt Download (1.8 KB) - added by mlh 4 years ago.

Change History

Changed 4 years ago by mlh

Changed 4 years ago by robertwb

  • milestone changed from wishlist to 0.11.1

Changed 4 years ago by robertwb

  • status changed from new to closed
  • resolution set to fixed

Works as expected. Committed  http://hg.cython.org/cython-devel/rev/620326b14c3f

This is another reason to keep the for...from syntax though.

Changed 4 years ago by robertwb

  • component changed from Code Generation to Python Semantics

Changed 4 years ago by robertwb

  • status changed from closed to reopened
  • resolution fixed deleted

Changed 4 years ago by robertwb

  • owner changed from somebody to robertwb
  • status changed from reopened to new

More optimal fix at #243

Changed 4 years ago by robertwb

  • status changed from new to closed
  • resolution set to fixed
Note: See TracTickets for help on using tickets.