Date: Tue, 14 Dec 2010 13:19:24 +0000 From: Michael Foord fuzzyman@voidspace.org.uk To: "Gregory P. Smith" greg@krypto.org Cc: Python-Ideas python-ideas@python.org Subject: Re: [Python-ideas] replace boolean methods on builtin types with properties [py4k?] Message-ID: AANLkTi=yEZ2i8j0CFF0V_P82S=WjULBFCq2gamO_xGu8@mail.gmail.com Content-Type: text/plain; charset="iso-8859-1"
On 13 December 2010 22:35, Gregory P. Smith greg@krypto.org wrote:
A hack could be done today to have these behave as both functions and properties by having the property return a callable bool derived class that returns itself. But that seems a bit too cool yet gross...
bool derived class... good luck with that. :-)
Michael
Well it it doesn't sound that odd to me. This it's one of the (few) things I miss from Matlab. Not that parentheses are optional for function calls, but that 'true', 'false', 'Inf' and 'NaN' act both as their respective values, and as functions. Like 'ones' and 'zeros' they can be called with a size tuple to get an array of nd-array of that value.
-Mark
On Thu, Dec 16, 2010 at 2:12 PM, M Daoust m_daoust@hotmail.com wrote:
A hack could be done today to have these behave as both functions and properties by having the property return a callable bool derived class that returns itself. But that seems a bit too cool yet gross...
That could break existing code. Suppose someone has something like f = random.choice([s.isalpha, None, s.isdigit]); truthiness = f() if f else f. OK, the random choice part is dumb, but I can see someone doing a test where they assume that methods like .isdigit will always return True and using that as a replacement for callable().
Well it it doesn't sound that odd to me. This it's one of the (few) things I miss from Matlab. Not that parentheses are optional for function calls, but that 'true', 'false', 'Inf' and 'NaN' act both as their respective values, and as functions. Like 'ones' and 'zeros' they can be called with a size tuple to get an array of nd-array of that value.
What's the advantage over [True] * n? Seems like a limited usecase, especially since the people who are really serious about arrays (vs. lists) are going to be using one of the numpy array classes.
-- Carl