List index out of range on scopeStack

Bug #1512184 reported by gozdal
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Pyflakes
Fix Released
Undecided
John Vandenberg

Bug Description

I am using flake8 on some Python code and after upgrading to 2.5.0 from 2.4.1 (which upgraded pyflakes) I started getting this error:

Traceback (most recent call last):
  File "/home/gozdalik/.virtualenvs/starfish/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/flake8/main.py", line 33, in main
    report = flake8_style.check_files()
  File "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/flake8/engine.py", line 176, in check_files
    return self._retry_serial(self._styleguide.check_files, paths=paths)
  File "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/flake8/engine.py", line 167, in _retry_serial
    return func(*args, **kwargs)
  File "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pep8.py", line 1670, in check_files
    self.input_dir(path)
  File "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pep8.py", line 1706, in input_dir
    runner(os.path.join(root, filename))
  File "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/flake8/engine.py", line 121, in input_file
    return fchecker.check_all(expected=expected, line_offset=line_offset)
  File "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pep8.py", line 1412, in check_all
    self.check_ast()
  File "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pep8.py", line 1358, in check_ast
    checker = cls(tree, self.filename)
  File "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/flake8/_pyflakes.py", line 43, in __init__
    withDoctest=self.withDoctest)
  File "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pyflakes/checker.py", line 294, in __init__
    self.handleChildren(tree)
  File "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pyflakes/checker.py", line 567, in handleChildren
    self.handleNode(node, tree)
  File "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pyflakes/checker.py", line 609, in handleNode
    handler(node)
  File "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pyflakes/checker.py", line 686, in GLOBAL
    global_scope = self.scopeStack[global_scope_index]
IndexError: list index out of range

The code I'm running pyflakes on is proprietary so unfortunately I can't share it. Any idea how to help debugging this issue?

Revision history for this message
John Vandenberg (jayvdb) wrote :

The relevant code was added in https://github.com/pyflakes/pyflakes/commit/03ffc76367c2910f37908105391c425cc4ae52da

And I am quite sure that "global_scope_index = 1 if self.withDoctest else 0" is wrong.

And https://github.com/pyflakes/pyflakes/pull/38 should fix the problem for you.

Revision history for this message
Phil Frost (bitglue) wrote :

Can you reduce the code that causes the failure to a minimal example that you can share?

Revision history for this message
gozdal (gozdal) wrote : Re: [Bug 1512184] Re: List index out of range on scopeStack
Download full text (3.3 KiB)

Do you have any tips how do I go doing that? From the stack it not obvious
to me which file is causing the problem.

wt., 3.11.2015 o 10:01 użytkownik Phil Frost <email address hidden> napisał:

> Can you reduce the code that causes the failure to a minimal example
> that you can share?
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1512184
>
> Title:
> List index out of range on scopeStack
>
> Status in Pyflakes:
> New
>
> Bug description:
> I am using flake8 on some Python code and after upgrading to 2.5.0
> from 2.4.1 (which upgraded pyflakes) I started getting this error:
>
> Traceback (most recent call last):
> File "/home/gozdalik/.virtualenvs/starfish/bin/flake8", line 11, in
> <module>
> sys.exit(main())
> File
> "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/flake8/main.py",
> line 33, in main
> report = flake8_style.check_files()
> File
> "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/flake8/engine.py",
> line 176, in check_files
> return self._retry_serial(self._styleguide.check_files, paths=paths)
> File
> "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/flake8/engine.py",
> line 167, in _retry_serial
> return func(*args, **kwargs)
> File
> "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pep8.py",
> line 1670, in check_files
> self.input_dir(path)
> File
> "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pep8.py",
> line 1706, in input_dir
> runner(os.path.join(root, filename))
> File
> "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/flake8/engine.py",
> line 121, in input_file
> return fchecker.check_all(expected=expected, line_offset=line_offset)
> File
> "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pep8.py",
> line 1412, in check_all
> self.check_ast()
> File
> "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pep8.py",
> line 1358, in check_ast
> checker = cls(tree, self.filename)
> File
> "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/flake8/_pyflakes.py",
> line 43, in __init__
> withDoctest=self.withDoctest)
> File
> "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pyflakes/checker.py",
> line 294, in __init__
> self.handleChildren(tree)
> File
> "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pyflakes/checker.py",
> line 567, in handleChildren
> self.handleNode(node, tree)
> File
> "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pyflakes/checker.py",
> line 609, in handleNode
> handler(node)
> File
> "/home/gozdalik/.virtualenvs/starfish/local/lib/python2.7/site-packages/pyflakes/checker.py",
> line 686, in GLOBAL
> global_scope = self.scopeStack[global_scope_index]
> IndexError: list index out of range
>
> The code I'm running pyflakes on is proprietary so unfortunately I
> can't share it. Any idea how to help...

Read more...

Revision history for this message
John Vandenberg (jayvdb) wrote :

This is easy to reproduce -- the problem occurs whenever `global` is used in the module scope when `self.withDoctest` is enabled, because the use of `self.withDoctest` is very wrong in determining scope levels.

Create a file `global_scope_bug.py` containing only `global foo`, and enable doctests.

PYFLAKES_DOCTEST=1 PYTHONPATH=. python -m pyflakes global_scope_bug.py

And my patch does fix it, but I'll refresh it to add tests and a more detailed commit message.

John Vandenberg (jayvdb)
Changed in pyflakes:
assignee: nobody → John Vandenberg (jayvdb)
status: New → Fix Committed
Phil Frost (bitglue)
Changed in pyflakes:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.