question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StopIteration raised every time

See original GitHub issue

In /text/init.py StopIteration gets raised every time

def _read(path, encoding="utf-8", comment=";;;"):
    """ Returns an iterator over the lines in the file at the given path,
        strippping comments and decoding each line to Unicode.
    """
    if path:
        if isinstance(path, str) and os.path.exists(path):
            # From file path.
            f = open(path, "r", encoding="utf-8")
        elif isinstance(path, str):
            # From string.
            f = path.splitlines()
        else:
            # From file or buffer.
            f = path
        for i, line in enumerate(f):
            line = line.strip(BOM_UTF8) if i == 0 and isinstance(line, str) else line
            line = line.strip()
            line = decode_utf8(line, encoding)
            if not line or (comment and line.startswith(comment)):
                continue
            yield line
    raise StopIteration

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:6
  • Comments:8

github_iconTop GitHub Comments

4reactions
agodbeherecommented, Oct 16, 2018

This issue is likely due to PEP-479 (https://www.python.org/dev/peps/pep-0479/)

This introduced a breaking change in the handling of “StopIteration” in generators that was activated by default in Python 3.7. In Python3.6, you would have seen a warning about the upcoming deprecation.

Someone should refer to PEP-479, in particular this section (https://www.python.org/dev/peps/pep-0479/#id38) to refactor this code. At first glance, I would bet that replacing raise StopIteration with return will do the trick.

3reactions
Raphencodercommented, Feb 25, 2019

Same here on python 3.7, any update planned?

Read more comments on GitHub >

github_iconTop Results From Across the Web

generator raised StopIteration" every time I try to run app ...
Before this change, a StopIteration raised by, or passing through, a generator simply ended the generator's useful life (the exception was ...
Read more >
PEP 479 – Change StopIteration handling inside generators
This PEP proposes a change to generators: when StopIteration is raised inside a generator, ... Each time it is (re)started, it may either...
Read more >
Complete Guide to Python StopIteration - eduCBA
When the specified number of iterations are done, StopIteration is raised by the next method in case of iterators and generators (works similar...
Read more >
"RuntimeError: generator raised StopIteration" every time I try ...
PYTHON : "RuntimeError: generator raised StopIteration " every time I try to run app [ Gift : Animated Search Engine ...
Read more >
3. Generators and Iterators | Advanced - Python Courses eu
Calling 'next' for the first time: Python Beginner Calling 'next' for ... Let's have a look at a generator in which we raise...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found