Skip to content

Conversation

fchapoton
Copy link
Contributor

Just fixing a few of the ruff --select=C4 suggestions in the combinat folder

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.

Comment on lines 1738 to 1741
try:
k = self.images()[0].length()
except IndexError:
return False
Copy link
Contributor

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

Copy link
Contributor Author

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).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I missed that.

Comment on lines 1738 to +1743
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())
Copy link
Contributor

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)

Copy link
Contributor Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine

Copy link

Documentation preview for this PR (built with commit b9ae35b; changes) is ready! 🎉

@vbraun vbraun merged commit 394f021 into sagemath:develop Apr 12, 2024
@fchapoton fchapoton deleted the some_C4_in_combinat branch April 13, 2024 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants