Message288149
One made-up use-case would be:
class LogLevel(Flags):
start = auto()
log1 = start | auto()
log2 = start | auto()
def fun(flags, *args):
if start in flags:
# open log file
if log1 in flags:
# Log important thing 1
if log2 in flags:
# Log important thing 2
if start in flags:
# close log file
Alternatively the same could be achieved using the existing capabilities with:
class LogLevel(Flags):
start = auto()
_log1 = auto()
log1 = start | _log1
_log2 = auto()
log2 = start | _log2
Which is less clear imho and could potentially a problem if somebody uses LogLevel._log2
Another alternative would be that within the function we would check for all cases. eg:
if (start in flags) or (log1 in flags) or (log2 in flags):
Which leads to less clear code and makes the code less maintainable when log3 gets introduced. In the existing case we need to remember to change the if clause both when opening and closing the file. After the proposed change we only need to change the enum.
I'm sure there are more use-cases for it. The one I'm using it for is a bit more convoluted that's why I'm not presenting it here. |
|
Date |
User |
Action |
Args |
2017-02-19 17:51:27 | magu | set | recipients:
+ magu, ethan.furman, mdk |
2017-02-19 17:51:27 | magu | set | messageid: <1487526687.27.0.3952705331.issue29594@psf.upfronthosting.co.za> |
2017-02-19 17:51:27 | magu | link | issue29594 messages |
2017-02-19 17:51:27 | magu | create | |
|