Hello developers,

I'm Sambodhi Roy, a new contributor exploring issue mailman#1122 in
Mailman Core (https://gitlab.com/mailman/mailman/-/issues/1122), and
wanted to share what I found and get some feedback before writing any
code as mentioned in the issue description.

The issue is summarised as follows:

Currently, ArchivePolicy is defined as a regular Enum in
mailman/interfaces/archiver.py:

      class ArchivePolicy(Enum):
              never = 0
              private = 1
              public = 2

ArchivePolicy.never is supposed to mean "don't archive," but when we
write if archive_policy: in the code, it evaluates as True even for
never as all Enum members are objects, and objects are truthy by
default. That's pretty counterintuitive and leads to confusion. The
comments in the issue proposes a few solutions to this issue:

The simpler solution is to add a __bool__ method to the existing Enum like so:
       def __bool__(self):
               return self.value != 0

Therefore, 'never' behaves as falsy without changing the several other
files that use this check in Postorius and HyperKitty. This method can
be a good addition for future use.

The other solution that the comment in the issue mentions is the use
of IntEnum instead of Enum. IntEnum uses integer comparisons and
arithmetic operations on enum values, so the issue is still solved but
it might lead to unexpected bugs elsewhere. Hence, I personally lean
towards the __bool__ method solution as it seems to be a smaller and
safer change.

Another thing I noticed is that the ArchivePolicy enum is also
duplicated in HyperKitty in hyperkitty/models/mailinglist.py, so
whatever we change should be applied there too.
Would be glad to write a patch after receiving more guidance on the
desired approach.

Thanks,
Sambodhi Roy
_______________________________________________
Mailman-Developers mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/mailman-developers.python.org/
Mailman FAQ: https://wiki.list.org/x/AgA3

Security Policy: https://wiki.list.org/x/QIA9

Reply via email to