-
-
Notifications
You must be signed in to change notification settings - Fork 661
some C4 fixes in combinat folder #37771
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
Conversation
src/sage/combinat/words/morphism.py
Outdated
try: | ||
k = self.images()[0].length() | ||
except IndexError: | ||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we consider these 4 lines an improvement over the 1 line that was there before?
Taking into account my comment above, I would just suggest:
if k is None:
return len(set(w.length() for w in self.images())) <= 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This avoids to compute all of them in case of failure (similar to all
and any
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I missed that.
if k is None: | ||
return len(set(w.length() for w in self.images())) == 1 | ||
else: | ||
return all(w.length() == k for w in self.images()) | ||
try: | ||
k = self.images()[0].length() | ||
except IndexError: | ||
return True | ||
return all(w.length() == k for w in self.images()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about rewriting it using an iterator? Just bikeshedding, feel free to ignore.
images = iter(self.images())
if k is None:
try:
k = next(images).length()
except StopIteration:
return True
return all(w.length() == k for w in images)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, this is a list, so there is no point, I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine
Documentation preview for this PR (built with commit b9ae35b; changes) is ready! 🎉 |
Just fixing a few of the
ruff --select=C4
suggestions in thecombinat
folder📝 Checklist