So, just to summarise the discussion:
There was some very mild support for readable pipelines, either using UFCS or
an alternative syntax, but the Pythonic way to make combinations of function
and method applications readable is to assign to variables over multiple lines.
Make the code read do
On Jun 8, 2014 9:56 PM, "Steven D'Aprano"
> > which means that hasattr (which is defined by
> > attempting to get the attribute and seeing if an exception is thrown)
> > has to return True.
>
> Yes. And this is a problem why?
Earlier in this thread I pointed out that returning True creates problem
On Mon, 09 Jun 2014 19:13:40 +1000, Chris Angelico wrote:
> On Mon, Jun 9, 2014 at 7:09 PM, Steven D'Aprano
> wrote:
>> On Mon, 09 Jun 2014 09:25:33 +0300, Marko Rauhamaa wrote:
>>
>>> In a word,
>>> Python has predefined a handful of *generic functions/methods*,
>>
>>
>> That's nine words :-)
>
On Mon, Jun 9, 2014 at 7:09 PM, Steven D'Aprano
wrote:
> On Mon, 09 Jun 2014 09:25:33 +0300, Marko Rauhamaa wrote:
>
>> In a word,
>> Python has predefined a handful of *generic functions/methods*,
>
>
> That's nine words :-)
I'll explain in two words: We propose to marry your daughters.
http://
On Mon, 09 Jun 2014 09:25:33 +0300, Marko Rauhamaa wrote:
> In a word,
> Python has predefined a handful of *generic functions/methods*,
That's nine words :-)
--
Steven D'Aprano
http://import-that.dreamwidth.org/
--
https://mail.python.org/mailman/listinfo/python-list
On Monday, 9 June 2014 04:44:22 UTC+1, Chris Angelico wrote:
> This could be solved, though, by having a completely different symbol
> that means "the thing on my left is actually the first positional
> parameter in the function call on my right", such as in your example:
>
> > plus(1, 2) | divid
Steven D'Aprano :
> On Sun, 08 Jun 2014 18:56:47 +0300, Marko Rauhamaa wrote:
>> In fact, what's the point of having the duality?
>>x < y <==> x.__lt__(y)
>
> [...]
>
> Consider x + y. What happens?
>
> #1 First, Python checks whether y is an instance of a *subclass* of x. If
> so, y gets pri
On Mon, Jun 9, 2014 at 1:53 PM, Steven D'Aprano
wrote:
>> which means that hasattr (which is defined by
>> attempting to get the attribute and seeing if an exception is thrown)
>> has to return True.
>
> Yes. And this is a problem why?
>
> Obviously it would mean that the semantics of hasattr will
On Sun, 08 Jun 2014 18:56:47 +0300, Marko Rauhamaa wrote:
> Paul Sokolovsky :
>
>> Python already has that - like, len(x) calls x.__len__() if it's
>> defined
>
> In fact, what's the point of having the duality?
>
>len(x) <==> x.__len__()
>
>x < y <==> x.__lt__(y)
>
>str(x) <==> x.
On Mon, 09 Jun 2014 02:48:13 +1000, Chris Angelico wrote:
> class Circle:
> def squared(self):
> raise NotImplementedError("Proven impossible in 1882")
>
> The trouble is that logically Circle does have a 'squared' attribute,
> while 3 doesn't; and yet Python guarantees this:
>
> foo
In article <53952807$0$29988$c3e8da3$54964...@news.astraweb.com>,
Steven D'Aprano wrote:
> (Note that Forth is brilliant here, as it exposes the argument stack and
> gives you a rich set of stack manipulation commands.)
As does PostScript (which, despite its reputation as a printer format,
is
On Mon, Jun 9, 2014 at 1:20 PM, Steven D'Aprano
wrote:
> On Mon, 09 Jun 2014 03:10:03 +1000, Chris Angelico wrote:
> [...]
>> Stdio.write_file("foo.png",Image.PNG.encode(Image.JPEG.decode(
>> Stdio.read_file("foo.jpg")).autocrop().rotate(0.5).grey()));
>>
>> With UFCS, that could become perfect da
On Mon, 09 Jun 2014 03:10:03 +1000, Chris Angelico wrote:
[...]
> Actually, this is something that I've run into sometimes. I can't think
> of any Python examples, partly because Python tends to avoid unnecessary
> method chaining, but the notion of "data flow" is a very clean one -
> look at shell
On Sunday, 8 June 2014 18:24:28 UTC+1, Ian wrote:
>
> But that would all be done in getattr, so I don't think it affects
> hasattr's implementation at all. Since hasattr doesn't push anything
> onto the stack, getattr doesn't have to care whether it was called
> directly from Python or indirectl
On Sun, Jun 8, 2014 at 11:13 AM, Chris Angelico wrote:
> On Mon, Jun 9, 2014 at 3:08 AM, Ian Kelly wrote:
>> On Sun, Jun 8, 2014 at 10:48 AM, Chris Angelico wrote:
>>> Except that it's even more complicated than that, because hasattr
>>> wasn't defined in your module, so it has a different set o
On Mon, Jun 9, 2014 at 3:08 AM, Ian Kelly wrote:
> On Sun, Jun 8, 2014 at 10:48 AM, Chris Angelico wrote:
>> Except that it's even more complicated than that, because hasattr
>> wasn't defined in your module, so it has a different set of globals.
>> In fact, this would mean that hasattr would bec
On Mon, Jun 9, 2014 at 2:24 AM, jongiddy wrote:
> A contrived example - which of these is easier to understand?
>
> from base64 import b64encode
>
> # works now
> print(b64encode(str(min(map(int, f.readlines()), key=lambda n: n % 10)),
> b'?-'))
>
> # would work with UFCS
> f.readlines().map(int)
On Sun, Jun 8, 2014 at 10:48 AM, Chris Angelico wrote:
> Except that it's even more complicated than that, because hasattr
> wasn't defined in your module, so it has a different set of globals.
> In fact, this would mean that hasattr would become quite useless.
hasattr is a builtin, so it has no
On Sun, Jun 8, 2014 at 2:15 AM, jongiddy wrote:
> One problem with your untested code, the superclasses would need to be
> checked before using UFCS, so the structure is:
>
> try:
> return super().__getattr__(attr)
> except AttributeError:
> # resolve using UFCS
And then if UFCS finds no
On Sun, Jun 8, 2014 at 10:24 AM, jongiddy wrote:
> A contrived example - which of these is easier to understand?
>
> from base64 import b64encode
>
> # works now
> print(b64encode(str(min(map(int, f.readlines()), key=lambda n: n % 10)),
> b'?-'))
>
> # would work with UFCS
> f.readlines().map(int
On Mon, Jun 9, 2014 at 1:39 AM, jongiddy wrote:
> e.g. I could define:
>
> def squared(x):
> return x * x
>
> i = 3
> i.squared() => 9
>
> j = AClassThatImplements__mul__()
> j.squared() => whatever j * j returns
>
> but also:
> class AnotherClass:
> def __mul__(self, other):
> ...
Hello,
On Sun, 08 Jun 2014 18:56:47 +0300
Marko Rauhamaa wrote:
> Paul Sokolovsky :
>
> > Python already has that - like, len(x) calls x.__len__() if it's
> > defined
>
> In fact, what's the point of having the duality?
>
>len(x) <==> x.__len__()
>
>x < y <==> x.__lt__(y)
>
>str
On Sun, Jun 8, 2014 at 9:56 AM, Marko Rauhamaa wrote:
> Paul Sokolovsky :
>
>> Python already has that - like, len(x) calls x.__len__() if it's
>> defined
>
> In fact, what's the point of having the duality?
>
>len(x) <==> x.__len__()
>
>x < y <==> x.__lt__(y)
>
>str(x) <==> x.__str__(
On Sunday, 8 June 2014 17:24:56 UTC+1, jongiddy wrote:
> # would work with UFCS
> f.readlines().map(int).min(key=lambda n: n %
> 10).str().b64encode(b'?-').print()
Ooops - map is the wrong way round to support UFCS in this case. However, with
UFCS, I could fix this by changing it to smap, and
On Sunday, 8 June 2014 13:06:08 UTC+1, Paul Sokolovsky wrote:
>
> Getting x.foo() to call foo(x) is what's bigger problem, which has
> serious performance and scoping confusion implications, as discussed in
> other mails.
The performance hit will only occur when the attribute access is about to
Paul Sokolovsky :
> Python already has that - like, len(x) calls x.__len__() if it's
> defined
In fact, what's the point of having the duality?
len(x) <==> x.__len__()
x < y <==> x.__lt__(y)
str(x) <==> x.__str__()
etc.
I suppose the principal reason is that people don't like UFCS.
On Sunday, 8 June 2014 15:59:14 UTC+1, Roy Smith wrote:
> Why? I assume a language which promoted the global namespace to be in
> the attribute search path (which, as far as I can tell, is what we're
> talking about here) would implement hasattr and raising AttributeError
> in a consistent w
In article <1dd863ba-09e5-439b-8669-db65f3e99...@googlegroups.com>,
jongiddy wrote:
> On Sunday, 8 June 2014 02:27:42 UTC+1, Gregory Ewing wrote:
> >
> > Also it doesn't sit well with Python's "one obvious
> > way to do it" guideline, because it means there are
> > *two* equally obvious ways t
Hello,
On Sun, 8 Jun 2014 01:26:04 -0700 (PDT)
jongiddy wrote:
> On Sunday, 8 June 2014 02:27:42 UTC+1, Gregory Ewing wrote:
> >
> > Also it doesn't sit well with Python's "one obvious
> > way to do it" guideline, because it means there are
> > *two* equally obvious ways to call a function.
>
Hello,
On Sun, 8 Jun 2014 01:15:43 -0700 (PDT)
jongiddy wrote:
> Thanks for the extensive feedback. Here's my thoughts on how to
> address these issues.
>
> On Saturday, 7 June 2014 20:20:48 UTC+1, Ian wrote:
> >
> > It's a nice feature in a statically typed language, but I'm not sure
> > ho
On Sunday, 8 June 2014 02:27:42 UTC+1, Gregory Ewing wrote:
>
> Also it doesn't sit well with Python's "one obvious
> way to do it" guideline, because it means there are
> *two* equally obvious ways to call a function.
Actually, one of the best arguments against introducing UFCS is that Python
On Sunday, 8 June 2014 02:27:42 UTC+1, Gregory Ewing wrote:
>
> Also it doesn't sit well with Python's "one obvious
> way to do it" guideline, because it means there are
> *two* equally obvious ways to call a function.
This provides a way to do something new (add class-optimized implementations
Thanks for the extensive feedback. Here's my thoughts on how to address these
issues.
On Saturday, 7 June 2014 20:20:48 UTC+1, Ian wrote:
>
> It's a nice feature in a statically typed language, but I'm not sure
> how well it would work in a language as dynamic as Python. There are
> some ques
Ian Kelly wrote:
It's a nice feature in a statically typed language, but I'm not sure
how well it would work in a language as dynamic as Python.
Also it doesn't sit well with Python's "one obvious
way to do it" guideline, because it means there are
*two* equally obvious ways to call a function
On Sat, Jun 7, 2014 at 12:45 AM, jongiddy wrote:
> The language D has a feature called Uniform Function Call Syntax, which
> allows instance methods to be resolved using function calls.
>
> In Python terms, the call:
>
> x.len()
>
> would first check if 'x' has a method 'len', and would then look
35 matches
Mail list logo