[Python-ideas] IntFlags
Neil Girdhar
mistersheik at gmail.com
Sat Mar 7 20:02:13 CET 2015
On Sat, Mar 7, 2015 at 1:51 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 03/07/2015 10:21 AM, Neil Girdhar wrote:
> > On Sat, Mar 7, 2015 at 10:05 AM, Ethan Furman wrote:
>
> >> or, even more illustratively, instead of:
> >>
> >> x = Stat(some_Stat_value_from_somewhere)
> >> x &= ~Stat.NOEXEC # to clear the bit
> >>
> >> we can have:
> >>
> >> x = Stat(some_Stat_value_from_somewhere)
> >> x.NOEXEC = False # much more readable
> >
> > Yes, +1
>
> >> Drat. Instances of Stat would not be immutuable, but that means they
> can't be thin wrappers around `int`, doesn't it?
> >> Which also means more work around C call sites. Drat and double-drat.
> >
> > Can't your C call sites cast the object to int?
>
> They could, but then you no longer have a drop-in replacement, which is
> what IntEnum is. Plus it's a hassle. So
> IntFlag (or whatever it's called) would to be immutable, which means no
> neat tricks like `obj.bit_name = False`.
>
A drop-in replacement for what? Is there a lot of Python code that
manipulates flags that you expect people to convert to IntFlags from int?
Isn't the point of IntFlags for writing new code?
> > Why do you need ~ at all? Do any API calls that you want to make want
> the inverted
> > flags? Isn't the only point of inverting the bits in order to clear a
> field?
>
> Hopefully somebody else can address this point.
>
> --
> ~Ethan~
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/python-ideas/L5KfCEXFaII/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> python-ideas+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
> --
>
> ---
> You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/python-ideas/L5KfCEXFaII/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> python-ideas+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150307/7bc651df/attachment.html>
More information about the Python-ideas
mailing list