Skip to content

Commit

Permalink
sagemathgh-37629: Implement a __bool__ for posets
Browse files Browse the repository at this point in the history
    
<!-- ^ 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 sagemath#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 sagemath#12345". -->

Fixes sagemath#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,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->
    
URL: sagemath#37629
Reported by: Travis Scrimshaw
Reviewer(s): Frédéric Chapoton
  • Loading branch information
Release Manager committed Mar 29, 2024
2 parents 142a1ff + a03127b commit d3ce9d0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/sage/combinat/posets/posets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,21 @@ def unwrap(self, element):
else:
return element.element

def __bool__(self) -> bool:
r"""
Return if ``self`` is empty or not.
EXAMPLES::
sage: P = Poset((divisors(15), attrcall("divides")), facade=True)
sage: bool(P)
True
sage: P = Poset()
sage: bool(P)
False
"""
return bool(self._elements)

def __contains__(self, x) -> bool:
r"""
Return ``True`` if ``x`` is an element of the poset.
Expand Down

0 comments on commit d3ce9d0

Please sign in to comment.