[issue26452] Wrong line number attributed to comprehension expressions

Karthikeyan Singaravelan report at bugs.python.org
Fri Sep 21 08:16:19 EDT 2018


Karthikeyan Singaravelan <tir.karthi at gmail.com> added the comment:

I think there have been some improvements merged with https://bugs.python.org/issue12458 . I am not sure if the patch covers more cases. I ran the tests attached in the patch and some of them cause RuntimeError in master.

# bpo26452.py

def f():
    return [j
            for i in range(3)
            if i]

f()

# Master 

./python.exe
Python 3.8.0a0 (heads/master:c510c6b8b6, Sep 21 2018, 11:10:24)
[Clang 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

./python.exe ../backups/bpo26452.py
Traceback (most recent call last):
  File "../backups/bpo26452.py", line 6, in <module>
    f()
  File "../backups/bpo26452.py", line 2, in f
    return [j
  File "../backups/bpo26452.py", line 2, in <listcomp>
    return [j
NameError: name 'j' is not defined


# Python 3.7

python3.7 ../backups/bpo26452.py
Traceback (most recent call last):
  File "../backups/bpo26452.py", line 6, in <module>
    f()
  File "../backups/bpo26452.py", line 3, in f
    for i in range(3)
  File "../backups/bpo26452.py", line 4, in <listcomp>
    if i]
NameError: name 'j' is not defined

# Tests

./python.exe ../backups/test26452.py
..F
======================================================================
FAIL: test_operators (__main__.TestPEP380Operation)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "../backups/test26452.py", line 21, in expect_line
    f()
  File "../backups/test26452.py", line 98, in f
    -
RuntimeError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "../backups/test26452.py", line 100, in test_operators
    self.expect_line(f, 3) # want 2
  File "../backups/test26452.py", line 26, in expect_line
    self.assertEqual(relative_line, expected_relative_line)
AssertionError: 2 != 3

----------------------------------------------------------------------
Ran 3 tests in 0.001s

FAILED (failures=1)


Thanks

----------
nosy: +xtreak

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue26452>
_______________________________________


More information about the Python-bugs-list mailing list