Sambodhi Roy via Mailman-Developers writes:
> 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:
The obvious solution is "don't do that". It's bad style to write
"if maybe_a_truthy:" unless the type is specifically designed for that.
(See for example "if x is not None:", and the interminable discussions
about adding null-propagating operators.) It's easy enough to write
"if policy is not never:" or "if policy in (private, public):" or even
match policy:
case never:
pass
case private | public:
handle_archive(*args)
"Don't do that" can be implemented as follows:
class NotABooleanError(SyntaxError): # This isn't quite true
pass
def __bool__(self):
raise NotABooleanError
Maybe I'll suggest that generically to python-dev, although they will
almost certainly reject it as backward incompatible with
def foo(x:Enum=None):
if x:
do_something(x)
which is probably all over the place in some code bases.
> 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.
Good point!
I wonder if it's possible to "import" ArchivePolicy via mailmanclient.
Probably not, since it's not a Model.
--
GNU Mailman consultant (installation, migration, customization)
Sirius Open Source https://www.siriusopensource.com/
Software systems consulting in Europe, North America, and Japan
_______________________________________________
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