Article 73WK1 [$] The troubles with Boolean inversion in Python

[$] The troubles with Boolean inversion in Python

by
jake
from LWN.net on (#73WK1)
The Python bitwise-inversion (or complement) operator, "~", behavespretty much as expected when it is applied to integers-it toggles everybit, from oneto zero and vice versa. It might be expected that applying theoperator to a non-integer, a boolfor example, would raise a TypeError, but, because thebool type is really an intin disguise, the complement operator is allowed, at least for now. Fornearly 15years (and perhaps longer), there have been discussions about theoddity of that behavior and whether it should be changed. Eventually,that resulted in the "feature" being deprecated, producing a warning, with removal slated forPython3.16 (due October 2027). That has led to some reconsideration and thedeprecation may itself be deprecated.
External Content
Source RSS or Atom Feed
Feed Location http://lwn.net/headlines/rss
Feed Title LWN.net
Feed Link https://lwn.net/
Reply 0 comments