Opened 8 years ago

Last modified 7 years ago

#6878 enhancement new

FlagConstants with equal values should compare as equal

Reported by: Jean-Paul Calderone Owned by:
Priority: normal Milestone:
Component: core Keywords:
Cc: Branch:
Author:

Description

By applying various operations, it's possible to get instances of FlagConstant (from the same Flags container) with the same value but which are not the same object:

>>> from twisted.python.constants import Flags, FlagConstant
>>> class X(Flags):
...     a = FlagConstant()
... 
>>> X.a is (X.a | X.a)
False
>>> 

These objects then do not compare equal though it would be much more useful if they did:

>>> X.a == (X.a | X.a)
False

Perhaps constructs such as this *should* produce the same object. Or perhaps FlagConstant should define equality (and not-equality) comparison such that instances with equal values are equal.

Change History (4)

comment:1 Changed 8 years ago by Wilfredo Sánchez Vega

Owner: set to Wilfredo Sánchez Vega
Status: newassigned

I'll try to work on this soon.

comment:2 Changed 8 years ago by Wilfredo Sánchez Vega

This brings up the question of whether it's important that flag constants from different sources should compare as equal. That is, in this case:

>>> from twisted.python.constants import Flags, FlagConstant
>>> class X(Flags):
...   x = FlagConstant()
... 
>>> class Y(Flags):
...   y = FlagConstant()
... 
>>> X.x.value == Y.y.value
True
>>> 

Would one expect X.x == Y.y to be true?

comment:3 Changed 8 years ago by Wilfredo Sánchez Vega

This relates to #6523 and should perhaps wait on it to merge, since there is a little bit of potential overlap.

comment:4 Changed 7 years ago by Wilfredo Sánchez Vega

Owner: Wilfredo Sánchez Vega deleted
Status: assignednew
Note: See TracTickets for help on using tickets.