Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #82367 > unrolled thread

is_<whatever_you_are_testing_for> as method or property?

Started byMateusz Loskot <mateusz@loskot.net>
First post2014-12-11 18:34 +0100
Last post2014-12-11 18:34 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  is_<whatever_you_are_testing_for> as method or property? Mateusz Loskot <mateusz@loskot.net> - 2014-12-11 18:34 +0100

#82367 — is_<whatever_you_are_testing_for> as method or property?

FromMateusz Loskot <mateusz@loskot.net>
Date2014-12-11 18:34 +0100
Subjectis_<whatever_you_are_testing_for> as method or property?
Message-ID<mailman.16859.1418320559.18130.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web