<div dir="ltr">For ~, I suggest either having an extra bit on the object that remembers negation or replacing the patterns a &= ~b with a.clear_flags(b) and a & ~b with a.without_flags(b) or something like that.<div><br>On Tuesday, March 3, 2015 at 10:54:15 AM UTC-5, Serhiy Storchaka wrote:<blockquote class="gmail_quote" style="margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">Enum and IntEnum classes allow constants to have nice str() and repr() 
<br>representations.
<br>
<br> >>> socket.AF_INET
<br><AddressFamily.AF_INET: 2>
<br> >>> socket.socket()
<br><socket.socket fd=3, family=AddressFamily.AF_INET, 
<br>type=SocketKind.SOCK_STREAM, proto=0, laddr=('0.0.0.0', 0)>
<br>
<br>But when integer constants are flags that should be ORed, IntEnum 
<br>doesn't help, because the result of bitwise OR of two IntEnum instances 
<br>is int, and this value can't be represented as IntEnum.
<br>
<br>We need new type IntFlags. It is like IntEnum, but has differences:
<br>
<br>1. The value of an instance should be not limited to the set of 
<br>predefined constants. It can be a combination of predefined constants or 
<br>even arbitrary integer.
<br>
<br>2. The result of "|", "&" and "~" operators for IntFlags arguments 
<br>should be an instance of the same IntFlags subclass.
<br>
<br>3. It should have nice str() and repr().
<br>
<br> >>> print(stat.S_IROTH | stat.S_IWOTH)
<br>stat.S_IROTH|stat.S_IWOTH
<br> >>> stat.S_IROTH | stat.S_IWOTH
<br><StatFlags.S_IROTH|S_IWOTH: 6>
<br>
<br>Any thoughts?
<br>
<br>______________________________<wbr>_________________
<br>Python-ideas mailing list
<br><a href="javascript:" target="_blank" gdf-obfuscated-mailto="8NS8bOg2rC0J" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">Python...@python.org</a>
<br><a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank" rel="nofollow" onmousedown="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-ideas\46sa\75D\46sntz\0751\46usg\75AFQjCNFj1EaNHnVmh20FnFPoUi4J-MpfQw';return true;" onclick="this.href='https://www.google.com/url?q\75https%3A%2F%2Fmail.python.org%2Fmailman%2Flistinfo%2Fpython-ideas\46sa\75D\46sntz\0751\46usg\75AFQjCNFj1EaNHnVmh20FnFPoUi4J-MpfQw';return true;">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a>
<br>Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHJOrArSUDKkjrnthO6_CznMzkPsA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fpython.org%2Fpsf%2Fcodeofconduct%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHJOrArSUDKkjrnthO6_CznMzkPsA';return true;">http://python.org/psf/<wbr>codeofconduct/</a>
<br></blockquote></div></div>