Skip to content

Commit d3ce9d0

Browse files
author
Release Manager
committed
gh-37629: Implement a __bool__ for posets <!-- ^ Please provide a concise and informative title. --> <!-- ^ Don't put issue numbers in the title, do this in the PR description below. --> <!-- ^ For example, instead of "Fixes #12345" use "Introduce new method to calculate 1 + 2". --> <!-- v Describe your changes below in detail. --> <!-- v Why is this change required? What problem does it solve? --> <!-- v If this PR resolves an open issue, please link to it here. For example, "Fixes #12345". --> Fixes #37547 by implementing a `__bool__` method. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [x] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #37629 Reported by: Travis Scrimshaw Reviewer(s): Frédéric Chapoton
2 parents 142a1ff + a03127b commit d3ce9d0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/sage/combinat/posets/posets.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,21 @@ def unwrap(self, element):
12301230
else:
12311231
return element.element
12321232

1233+
def __bool__(self) -> bool:
1234+
r"""
1235+
Return if ``self`` is empty or not.
1236+
1237+
EXAMPLES::
1238+
1239+
sage: P = Poset((divisors(15), attrcall("divides")), facade=True)
1240+
sage: bool(P)
1241+
True
1242+
sage: P = Poset()
1243+
sage: bool(P)
1244+
False
1245+
"""
1246+
return bool(self._elements)
1247+
12331248
def __contains__(self, x) -> bool:
12341249
r"""
12351250
Return ``True`` if ``x`` is an element of the poset.

0 commit comments

Comments
 (0)