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

Py3: Fix DeprecationWarning: generator X raised StopIteration for combinat/words #26458

Closed
vinklein mannequin opened this issue Oct 10, 2018 · 11 comments
Closed

Py3: Fix DeprecationWarning: generator X raised StopIteration for combinat/words #26458

vinklein mannequin opened this issue Oct 10, 2018 · 11 comments

Comments

@vinklein
Copy link
Mannequin

vinklein mannequin commented Oct 10, 2018

CC: @embray @seblabbe

Component: python3

Author: Vincent Klein

Branch/Commit: f28b724

Reviewer: Frédéric Chapoton

Issue created by migration from https://trac.sagemath.org/ticket/26458

@vinklein vinklein mannequin added this to the sage-8.4 milestone Oct 10, 2018
@vinklein vinklein mannequin added c: python3 labels Oct 10, 2018
@vinklein
Copy link
Mannequin Author

vinklein mannequin commented Oct 10, 2018

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented Oct 10, 2018

Commit: f28b724

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented Oct 10, 2018

Author: Vincent Klein

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented Oct 10, 2018

New commits:

f28b724Trac #26458: Py3 combinat/words fix deprecation warning ...

@vinklein vinklein mannequin added the s: needs review label Oct 10, 2018
@fchapoton
Copy link
Contributor

comment:4

This is working, but I am not convinced at all that this is the right way to do that. @embray, any opinion ?

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented Oct 11, 2018

comment:5

I agree try: ... except StopIteration are sort of ugly, i use them when i don't find more concise ways to do that.

That being said this syntax is consistent with pep-0479

@vinklein
Copy link
Mannequin Author

vinklein mannequin commented Oct 11, 2018

comment:6

I have a way to avoid try except for abstract_word.py

diff --git a/src/sage/combinat/words/abstract_word.py b/src/sage/combinat/words/abstract_word.py
index 3e36111..16fa382 100644
--- a/src/sage/combinat/words/abstract_word.py
+++ b/src/sage/combinat/words/abstract_word.py
@@ -1370,16 +1370,17 @@ class Word_class(SageObject):
             ...
             TypeError: mod(=a) must be None or an integer
         """
+        if self.is_empty()
+            return
+
         if mod in (None, 0):
             i = iter(self)
             j = iter(self)
+            next(j)
 
-            try:
-                next(j)
-                while True:
-                    yield next(j) - next(i)
-            except StopIteration:
-                return
+            for a, b in zip(i,j):
+                yield a -b
+            return
 
         elif mod in ZZ:
             Zn = Integers(mod)

Tell me what you prefer.

@fchapoton
Copy link
Contributor

comment:7

ok, let it be.

@fchapoton
Copy link
Contributor

Reviewer: Frédéric Chapoton

@vbraun
Copy link
Member

vbraun commented Oct 20, 2018

@embray
Copy link
Contributor

embray commented Oct 28, 2018

comment:9

This should be re-targeted for 8.5.

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

No branches or pull requests

3 participants