Skip to content

Conversation

@einarf
Copy link
Member

@einarf einarf commented Jul 30, 2018

Actively catch StopIteration. Generators no longer consume this exception.

This was introduced in PEP 479

Actively catch StopIteration. Generators no longer consume this exception. This was introduced in PEP 479
@einarf
Copy link
Member Author

einarf commented Jul 30, 2018

To explain this a bit further:

We fill lists data using a generator like this:

vertices += list(self.consume_faces())

This is much simpler and efficient than constantly calling append().

consume_faces keeps yielding values and the list will keep consuming them.

def consume_faces(self): while True: # This method calls ``next()`` on a generator reading from the file. # It will ``raise StopIteration`` when there are no more lines self.next_line()

In python 3.7 a generator no longer consumes the StopIteration exception and considers it a runtime error. Instead we need to catch the exception and return from the method instead.

def consume_faces(self): while True: try: self.next_line() except StopIteration: break
@greenmoss
Copy link
Collaborator

LGTM; thanks!

@greenmoss greenmoss merged commit ea28844 into pywavefront:master Jul 30, 2018
@einarf
Copy link
Member Author

einarf commented Aug 1, 2018

Should probably release a new version before closing this one. The issue is not resolved from the end users perspective.

@einarf einarf mentioned this pull request Aug 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants