Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP 479 breaks functions that are based on generators in Python 3.7 #168

Closed
nicolastorzec opened this issue Aug 15, 2018 · 2 comments
Closed

Comments

@nicolastorzec
Copy link

Hi,

PEP 479 changes the way StopIteration is handled within generators. Pre-3.7, generators used to exit gracefully, but in 3.7 they result in a RuntimeError.

As a result, functions like successors() or subgraph() are no longer working and raise a RuntimeError with 3.7.

Trace below:

---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
~/Workspace/VirtualEnv/py370/lib/python3.7/site-packages/pygraphviz/agraph.py in successors_iter(self, n)
    809             eh = gv.agnxtout(self.handle, eh)
--> 810         raise StopIteration
    811 

StopIteration: 

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
<ipython-input-14-39154a6704d5> in <module>()
----> 1 Image(gpt.draw(root='ROOT', max_depth=1), retina=True)

~/Workspace/gptlib.py in draw(self, root, max_depth, format, filename)
    203                     yield from get_subtree_nodes(s, d-1)
    204 
--> 205         sg = self.__gpt_graph.subgraph([root] + [n for n in get_subtree_nodes(root, max_depth)])
    206 
    207         sg.layout(prog='dot')

~/Workspace/gptlib.py in <listcomp>(.0)
    203                     yield from get_subtree_nodes(s, d-1)
    204 
--> 205         sg = self.__gpt_graph.subgraph([root] + [n for n in get_subtree_nodes(root, max_depth)])
    206 
    207         sg.layout(prog='dot')

~/Workspace/ProductKG/GoogleProductTaxonomy/gptlib.py in get_subtree_nodes(n, d)
    199 
    200             if d > 0:
--> 201                 for s in self.__gpt_graph.successors(n):
    202                     yield s
    203                     yield from get_subtree_nodes(s, d-1)

~/Workspace/VirtualEnv/py370/lib/python3.7/site-packages/pygraphviz/agraph.py in successors(self, n)
    814     def successors(self, n):
    815         """Return list of successor nodes of n."""
--> 816         return list(self.successors_iter(n))
    817 
    818 

RuntimeError: generator raised StopIteration
@nicolastorzec nicolastorzec changed the title PEP 479 breaks generator functions like successors() and subgraph() in Python 3.7 PEP 479 breaks generator functions in Python 3.7 Aug 15, 2018
@nicolastorzec nicolastorzec changed the title PEP 479 breaks generator functions in Python 3.7 PEP 479 breaks functions based on generators in Python 3.7 Aug 15, 2018
@nicolastorzec nicolastorzec changed the title PEP 479 breaks functions based on generators in Python 3.7 PEP 479 breaks pygrahviz functions that are based on generators in Python 3.7 Aug 15, 2018
@nicolastorzec nicolastorzec changed the title PEP 479 breaks pygrahviz functions that are based on generators in Python 3.7 PEP 479 breaks functions that are based on generators in Python 3.7 Aug 15, 2018
@dschult
Copy link
Contributor

dschult commented Aug 15, 2018

I think these are fixed in #164. We are preparing to make a release with the updates.

@nicolastorzec
Copy link
Author

I git cloned and installed the upcoming release (i.e. pygraphviz-1.5.dev0-py3.7.egg-inf), and it indeed fixed the issues I had with subgraphs(), successors(), and other generator functions.

Thanks @dschult.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants