Re: try/except/finally

2014-06-08 Thread Marko Rauhamaa
Mark Lawrence : >>> A return statement inside a finally block is code smell. >> Not to my nose. It seems like a perfectly reasonable thing to do. > I agree, the code smell is the return in the except block. Here's a regular pattern that I use for nonblocking I/O: def poll(self): try

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
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

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
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

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
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

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Paul Sokolovsky
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

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Paul Sokolovsky
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. >

Re: OT: This Swift thing

2014-06-08 Thread MRAB
On 2014-06-07 17:18, Marko Rauhamaa wrote: Roy Smith : The original MacOS was written in Pascal (both applications and kernel). Being able to touch memory locations or registers requires no more than a few short glue routines written in assembler. Pascal is essentially equivalent to C, except

Re: OT: This Swift thing

2014-06-08 Thread Roy Smith
In article <5393dd6a$0$29988$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > On Sat, 07 Jun 2014 20:09:37 -0400, Roy Smith wrote: > > > We've also got machines that are so fast, it's not longer critical that > > we squeeze out every last iota of performance. Oh, but wait, now we'

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Roy Smith
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

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
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

Re: OT: This Swift thing

2014-06-08 Thread Gene Heskett
On Sunday 08 June 2014 10:51:24 Roy Smith did opine And Gene did reply: > In article <5393dd6a$0$29988$c3e8da3$54964...@news.astraweb.com>, > > Steven D'Aprano wrote: > > On Sat, 07 Jun 2014 20:09:37 -0400, Roy Smith wrote: > > > We've also got machines that are so fast, it's not longer critical

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Marko Rauhamaa
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.

Re: OT: This Swift thing

2014-06-08 Thread Roy Smith
In article , Gene Heskett wrote: > You may want to reconsider that statement after the first fan failure in > your mini. We've had quite a few Mac's in the tv station, as video > servers, graphics composers, etc. The airflow for cooling in them is > controlled by baffles to get the maximum

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
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

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
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

Python Team(...)

2014-06-08 Thread Carlos Anselmo Dias
Hi ... Here I'm seeking for my team of developers/programmers in Python ... I'd like to ask you to provide me contacts of people interested ... I'm sending you one script attachment(...) ... I'll manage them naturally knowing that the detail is wide ... programming languages, Databases,

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Ian Kelly
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__(

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Paul Sokolovsky
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

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Chris Angelico
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): > ...

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Ian Kelly
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

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Ian Kelly
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

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Ian Kelly
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

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Chris Angelico
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)

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Chris Angelico
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

Re: OT: This Swift thing

2014-06-08 Thread Gene Heskett
On Sunday 08 June 2014 12:09:41 Roy Smith did opine And Gene did reply: > In article , > > Gene Heskett wrote: > > You may want to reconsider that statement after the first fan failure > > in your mini. We've had quite a few Mac's in the tv station, as > > video servers, graphics composers, etc

Re: OT: This Swift thing

2014-06-08 Thread Chris Angelico
On Mon, Jun 9, 2014 at 3:14 AM, Gene Heskett wrote: > I have lost several nvidia video cards over the years from fan > failures. >From a discussion on one of Threshold RPG's out-of-character channels: Kurdt: I wouldn't disturb the fan controller. Kurdt: Ever seen an AMD without a fan? ;) Leshrak

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Ian Kelly
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

Re: try/except/finally

2014-06-08 Thread Joshua Landau
On 8 June 2014 08:12, Marko Rauhamaa wrote: > > Does anyone have an example motivating a return from finally? It seems > to me it would always be a bad idea as it silently clears all unexpected > exceptions. In a general sense: try: something_that_can_break() return foo() # b

Re: os.startfile hanging onto the launched app, or my IDE?

2014-06-08 Thread Ian Kelly
On Fri, Jun 6, 2014 at 2:34 PM, Josh English wrote: > I have been using os.startfile(filepath) to launch files I've created in > Python, mostly Excel spreadsheets, text files, or PDFs. > > When I run my script from my IDE, the file opens as I expect. But if I go > back to my script and re-run it

Re: try/except/finally

2014-06-08 Thread Joshua Landau
On 6 June 2014 18:39, Roy Smith wrote: > > The only way I can think of to bypass a finally block would be to call > os._exit(), or send yourself a kill signal. If you're willing to use implementation details... --- # BreakN.py import sys # Turn tracing on if it is off if sys.gettrace() is Non

Re: try/except/finally

2014-06-08 Thread Ian Kelly
On Sun, Jun 8, 2014 at 12:02 PM, Ian Kelly wrote: > On Sun, Jun 8, 2014 at 11:57 AM, Joshua Landau wrote: >> On 8 June 2014 08:12, Marko Rauhamaa wrote: >>> >>> Does anyone have an example motivating a return from finally? It seems >>> to me it would always be a bad idea as it silently clears al

Re: try/except/finally

2014-06-08 Thread Ian Kelly
On Sun, Jun 8, 2014 at 11:57 AM, Joshua Landau wrote: > On 8 June 2014 08:12, Marko Rauhamaa wrote: >> >> Does anyone have an example motivating a return from finally? It seems >> to me it would always be a bad idea as it silently clears all unexpected >> exceptions. > > In a general sense: > >

Re: OT: This Swift thing

2014-06-08 Thread Sturla Molden
Chris Angelico wrote: > Kurdt: I wouldn't disturb the fan controller. > Kurdt: Ever seen an AMD without a fan? ;) > Leshrak: heh, yeah > Leshrak: actually. it's not a pretty smell > Kurdt: Especially when it's overclocked. It goes FT in under two seconds. > > I think that's about right. On

Re: Decorating one method of a class C with another method of class C?

2014-06-08 Thread Dan Stromberg
On 6/6/14, Ben Finney wrote: > Dan Stromberg writes: > >> Is there a way of decorating method1 of class C using method2 of class >> C? > > Can you give a concrete example (i.e. not merely hypothetical) where > this would be a useful feature (i.e. an actual improvement over the > absence of the fe

Re: OT: This Swift thing

2014-06-08 Thread Chris Angelico
On Mon, Jun 9, 2014 at 4:09 AM, Sturla Molden wrote: > Chris Angelico wrote: > >> Kurdt: I wouldn't disturb the fan controller. >> Kurdt: Ever seen an AMD without a fan? ;) >> Leshrak: heh, yeah >> Leshrak: actually. it's not a pretty smell >> Kurdt: Especially when it's overclocked. It goes FZZ

Re: Decorating one method of a class C with another method of class C?

2014-06-08 Thread Chris Angelico
On Mon, Jun 9, 2014 at 4:04 AM, Dan Stromberg wrote: > I have a class that's operating on a socket. > > I'd like to have simple operations on that socket like "list > configured hosts", "allow connection to host", etc. And I'd like them > to be decorated with "reconnected_to_server_if_needed". >

Re: OT: This Swift thing

2014-06-08 Thread Carlos Anselmo Dias
On 06/08/2014 06:14 PM, Gene Heskett wrote: On Sunday 08 June 2014 12:09:41 Roy Smith did opine And Gene did reply: In article , Gene Heskett wrote: You may want to reconsider that statement after the first fan failure in your mini. We've had quite a few Mac's in the tv station, as video

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
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

Re: Decorating one method of a class C with another method of class C?

2014-06-08 Thread Ben Finney
Dan Stromberg writes: > I'd like to have simple operations on that socket like "list > configured hosts", "allow connection to host", etc. And I'd like them > to be decorated with "reconnected_to_server_if_needed". The ‘reconnected_to_server_if_needed’ method, if I understand your original post

Re: OT: This Swift thing

2014-06-08 Thread Sturla Molden
Chris Angelico wrote: >>> Kurdt: I wouldn't disturb the fan controller. >>> Kurdt: Ever seen an AMD without a fan? ;) >>> Leshrak: heh, yeah >>> Leshrak: actually. it's not a pretty smell >>> Kurdt: Especially when it's overclocked. It goes FT in under two >>> seconds. >>> >>> I think that

Re: OT: This Swift thing

2014-06-08 Thread Steven D'Aprano
On Mon, 09 Jun 2014 04:16:24 +1000, Chris Angelico wrote: > On Mon, Jun 9, 2014 at 4:09 AM, Sturla Molden > wrote: >> Chris Angelico wrote: >> >>> Kurdt: I wouldn't disturb the fan controller. Kurdt: Ever seen an AMD >>> without a fan? ;) Leshrak: heh, yeah >>> Leshrak: actually. it's not a pre

Re: OT: This Swift thing

2014-06-08 Thread Rustom Mody
On Monday, June 9, 2014 7:14:24 AM UTC+5:30, Steven D'Aprano wrote: > On Mon, 09 Jun 2014 04:16:24 +1000, Chris Angelico wrote: > > wrote: > >> Chris Angelico wrote: > >>> Kurdt: I wouldn't disturb the fan controller. Kurdt: Ever seen an AMD > >>> without a fan? ;) Leshrak: heh, yeah > >>> Leshrak

Re: OT: This Swift thing

2014-06-08 Thread Rustom Mody
On Monday, June 9, 2014 5:04:05 AM UTC+5:30, Sturla Molden wrote: > Chris Angelico wrote: > >>> Kurdt: I wouldn't disturb the fan controller. > >>> Kurdt: Ever seen an AMD without a fan? ;) > >>> Leshrak: heh, yeah > >>> Leshrak: actually. it's not a pretty smell > >>> Kurdt: Especially when it's

Re: OT: This Swift thing

2014-06-08 Thread Rustom Mody
On Monday, June 9, 2014 7:14:24 AM UTC+5:30, Steven D'Aprano wrote: > On Mon, 09 Jun 2014 04:16:24 +1000, Chris Angelico wrote: > > wrote: > The fact that CPUs need anything more than a passive heat sink is > *exactly* the problem. A car engine has to move anything up to a tonne of > steel around

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Steven D'Aprano
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

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Chris Angelico
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

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Roy Smith
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

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Steven D'Aprano
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

Re: OT: This Swift thing

2014-06-08 Thread Steven D'Aprano
On Sun, 08 Jun 2014 19:24:52 -0700, Rustom Mody wrote: > On Monday, June 9, 2014 7:14:24 AM UTC+5:30, Steven D'Aprano wrote: >> The fact that CPUs need anything more than a passive heat sink is >> *exactly* the problem. A car engine has to move anything up to a tonne >> of steel around at 100kph

Re: OT: This Swift thing

2014-06-08 Thread Chris Angelico
On Mon, Jun 9, 2014 at 11:44 AM, Steven D'Aprano wrote: > The fact that CPUs need anything more than a passive heat sink is > *exactly* the problem. A car engine has to move anything up to a tonne of > steel around at 100kph or more, and depending on the design, they can get > away with air-coolin

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Steven D'Aprano
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.

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Chris Angelico
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

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread Marko Rauhamaa
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

Re: OT: This Swift thing

2014-06-08 Thread Rustom Mody
On Monday, June 9, 2014 9:50:38 AM UTC+5:30, Steven D'Aprano wrote: > On Sun, 08 Jun 2014 19:24:52 -0700, Rustom Mody wrote: > > > > On Monday, June 9, 2014 7:14:24 AM UTC+5:30, Steven D'Aprano wrote: > >> CPU technology is the triumph of brute force over finesse. > > > > If you are arguing that

Re: Uniform Function Call Syntax (UFCS)

2014-06-08 Thread jongiddy
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