This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author magu
Recipients ethan.furman, magu, mdk
Date 2017-02-19.17:51:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1487526687.27.0.3952705331.issue29594@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-02-19 17:51:27magusetrecipients: + magu, ethan.furman, mdk
2017-02-19 17:51:27magusetmessageid: <1487526687.27.0.3952705331.issue29594@psf.upfronthosting.co.za>
2017-02-19 17:51:27magulinkissue29594 messages
2017-02-19 17:51:27magucreate