Skip to content

Commit

Permalink
Fix DeprecationWarning's for ~(bool) on CPython 3.12+
Browse files Browse the repository at this point in the history
  • Loading branch information
skirpichev committed Aug 17, 2023
1 parent 3700390 commit c5642c1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
21 changes: 5 additions & 16 deletions diofant/logic/boolalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ class when they evaluate to true.
true
>>> ~true
false
>>> ~True
-2
>>> not True
False
>>> Or(True, False)
true
Expand Down Expand Up @@ -414,19 +414,8 @@ class Not(BooleanFunction):
>>> ~((x | y) & (~x | ~y))
~((x | y) & (~x | ~y))
Notes
=====
The ``~`` operator is provided as a convenience, but note that its use
here is different from its normal use in Python, which is bitwise
not. In particular, ``~a`` and ``Not(a)`` will be different if ``a`` is
an integer. Furthermore, since bools in Python subclass from ``int``,
``~True`` is the same as ``~1`` which is ``-2``, which has a boolean
value of True. To avoid this issue, use the Diofant boolean types
``true`` and ``false``.
>>> ~True
-2
>>> not True
False
>>> ~true
false
Expand Down Expand Up @@ -536,7 +525,7 @@ def __new__(cls, *args, **kwargs):
for j in range(i + 1, len(rel)):
rj, cj = rel[j][:2]
if cj == nc:
odd = ~odd
odd = not odd
break
if cj == c:
break
Expand Down
1 change: 0 additions & 1 deletion diofant/tests/combinatorics/test_permutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def test_Permutation():

assert rmul(~p, p).is_Identity
assert (~p)**13 == Permutation([5, 2, 0, 4, 6, 1, 3])
assert ~(r**2).is_Identity
assert p.max() == 6
assert p.min() == 0

Expand Down

0 comments on commit c5642c1

Please sign in to comment.