is_<whatever_you_are_testing_for> as method or property?
Mateusz Loskot
mateusz at loskot.net
Thu Dec 11 12:34:25 EST 2014
Hi,
I have been looking at various places to answer this dilemma:
If a class member function simply tests something and
returns a b::oolean call it
def is_<whatever_you_are_testing_for>():
pass
like 'is_even'.
Should I define it as a classic method
def is_even(self):
pass
or as a property
@property
def is_even(self):
pass
The question above is based on similar question I found [1],
but that one is specifically about naming.
I'm trying to solve the aspect of implementation of such predicate.
I've looked into the Python 3.4 libs and most of such functions is
realised as a classic method, but in several cases they are
defined with @property decorator, for example:
email.message.MIMEPart.iis_attachment
ipaddress._BaseNetwork.is_multicast
ipaddress._BaseNetwork is_reserved
and a few more.
So, a classic method or a property, which one is the Pythonic 3 way for
such member predicates?
[1] *Naming Conventions* by Thorsten Kampe
https://mail.python.org/pipermail/python-list/2007-June/438156.html
Best regards,
--
Mateusz Loskot, http://mateusz.loskot.net
More information about the Python-list
mailing list