Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#26458 closed enhancement (fixed)

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

Reported by: vklein Owned by:
Priority: major Milestone: sage-8.5
Component: python3 Keywords:
Cc: embray, slabbe Merged in:
Authors: Vincent Klein Reviewers: Frédéric Chapoton
Report Upstream: N/A Work issues:
Branch: f28b724 (Commits, GitHub, GitLab) Commit: f28b724d8974fedceda2fccf79d4569ab34d2f3a
Dependencies: Stopgaps:

Status badges


Change History (9)

comment:1 Changed 4 years ago by vklein

  • Branch set to u/vklein/py3__fix_deprecationwarning__generator_x_raised_stopiteration_for_combinat_words

comment:2 Changed 4 years ago by vklein

  • Authors set to Vincent Klein
  • Commit set to f28b724d8974fedceda2fccf79d4569ab34d2f3a

New commits:

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

comment:3 Changed 4 years ago by vklein

  • Status changed from new to needs_review

comment:4 Changed 4 years ago by chapoton

  • Cc embray added

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

comment:5 Changed 4 years ago by vklein

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

comment:6 Changed 4 years ago by vklein

I have a way to avoid try except for

diff --git a/src/sage/combinat/words/ b/src/sage/combinat/words/
index 3e36111..16fa382 100644
--- a/src/sage/combinat/words/
+++ b/src/sage/combinat/words/
@@ -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.

comment:7 Changed 4 years ago by chapoton

  • Cc slabbe added
  • Reviewers set to Frédéric Chapoton
  • Status changed from needs_review to positive_review

ok, let it be.

comment:8 Changed 4 years ago by vbraun

  • Branch changed from u/vklein/py3__fix_deprecationwarning__generator_x_raised_stopiteration_for_combinat_words to f28b724d8974fedceda2fccf79d4569ab34d2f3a
  • Resolution set to fixed
  • Status changed from positive_review to closed

comment:9 Changed 4 years ago by embray

  • Milestone changed from sage-8.4 to sage-8.5

This should be re-targeted for 8.5.

Note: See TracTickets for help on using tickets.