Re: [Python-Dev] why different between staticmethod and classmethod on non-callable object?

2009-09-01 Thread Terry Reedy
P.J. Eby wrote: At 08:50 PM 9/1/2009 -0400, Terry Reedy wrote: Greg Ewing wrote: Benjamin Peterson wrote: It depends on whether you're keeping the "callable" object around or not. Somebody could add a __call__ method later. Good point. Removing the check sounds like the right thing to do, th

Re: [Python-Dev] why different between staticmethod and classmethod on non-callable object?

2009-09-01 Thread P.J. Eby
At 08:50 PM 9/1/2009 -0400, Terry Reedy wrote: Greg Ewing wrote: Benjamin Peterson wrote: It depends on whether you're keeping the "callable" object around or not. Somebody could add a __call__ method later. Good point. Removing the check sounds like the right thing to do, then. Both classm

Re: [Python-Dev] why different between staticmethod and classmethod on non-callable object?

2009-09-01 Thread Terry Reedy
Greg Ewing wrote: Benjamin Peterson wrote: It depends on whether you're keeping the "callable" object around or not. Somebody could add a __call__ method later. Good point. Removing the check sounds like the right thing to do, then. Both classmethod & staticmethod are documented as having a

Re: [Python-Dev] why different between staticmethod and classmethod on non-callable object?

2009-09-01 Thread Raymond Hettinger
On Sep 1, 2009, at 2:54 PM, Benjamin Peterson wrote: 2009/9/1 Brett Cannon : On Tue, Sep 1, 2009 at 07:21, Benjamin Peterson wrote: 2009/8/31 xiaobing jiang : My idea is: here, the two functions (or maybe classes) should have the same behavior). so is this a bug or something I missing ?

Re: [Python-Dev] why different between staticmethod and classmethod on non-callable object?

2009-09-01 Thread Greg Ewing
Benjamin Peterson wrote: It depends on whether you're keeping the "callable" object around or not. Somebody could add a __call__ method later. Good point. Removing the check sounds like the right thing to do, then. -- Greg ___ Python-Dev mailing lis

Re: [Python-Dev] why different between staticmethod and classmethod on non-callable object?

2009-09-01 Thread Benjamin Peterson
2009/9/1 Greg Ewing : > Brett Cannon wrote: >> >> It isn't like it is checking >> explicitly for a function or method, just that it can be called which >> seems reasonable to me (unless PyCallable_Check() is as off as >> callable() was). > > I think it just checks that there's something in the > tp

Re: [Python-Dev] why different between staticmethod and classmethod on non-callable object?

2009-09-01 Thread Greg Ewing
Brett Cannon wrote: It isn't like it is checking explicitly for a function or method, just that it can be called which seems reasonable to me (unless PyCallable_Check() is as off as callable() was). I think it just checks that there's something in the tp_call slot, which is reasonable -- if it'

Re: [Python-Dev] Whether to call Py_Finalize when exiting from the child process of a fork from a spawned thread

2009-09-01 Thread Greg Ewing
Reid Kleckner wrote: On one hand, you may not want to call the user's atexit handlers multiple times from different processes if they have externally visible effects. On the other hand, people seem to assume that Py_Finalize will be called at process exit to do various cleanups. On the third h

Re: [Python-Dev] why different between staticmethod and classmethod on non-callable object?

2009-09-01 Thread Brett Cannon
On Tue, Sep 1, 2009 at 14:54, Benjamin Peterson wrote: > 2009/9/1 Brett Cannon : >> On Tue, Sep 1, 2009 at 07:21, Benjamin Peterson wrote: >>> 2009/8/31 xiaobing jiang : My idea is: here, the two functions (or maybe classes) should have the same behavior). so is this a bug or somethi

Re: [Python-Dev] [OT] implicit return values

2009-09-01 Thread Greg Ewing
Le mardi 01 septembre 2009 à 15:09 +0200, Xavier Morel a écrit : "We" are not Erlang, Smalltalk, OCaml or Haskell either, sadly. IIRC, the default return value of a Smalltalk method is self, not the last thing evaluated. (And no, that's not going to happen in Python either -- the BDFL has rej

Re: [Python-Dev] default of returning None hurts performance?

2009-09-01 Thread Greg Ewing
Xavier Morel wrote: I fail to grasp the unpredictability of "the last expression evaluated in the body of a function is its return value". It's unpredictable in the sense that if you're writing a function that's not intended to return a value, you're not thinking about what the last call you

Re: [Python-Dev] why different between staticmethod and classmethod on non-callable object?

2009-09-01 Thread Benjamin Peterson
2009/9/1 Brett Cannon : > On Tue, Sep 1, 2009 at 07:21, Benjamin Peterson wrote: >> 2009/8/31 xiaobing jiang : >>> My idea is: here, the two functions (or maybe classes) should have the >>> same behavior). >>> so is this a bug or something I missing ? >> >> I think they should both not check their

Re: [Python-Dev] Whether to call Py_Finalize when exiting from the child process of a fork from a spawned thread

2009-09-01 Thread Martin v. Löwis
>> Standard POSIX fork semantics should be a guidance. IIUC, termination >> of the last thread is equivalent to calling exit(0) (although return >> from main() still means that exit is invoked right away, and the return >> value of main is the exit code - right?). Calling exit means to call >> all

Re: [Python-Dev] Whether to call Py_Finalize when exiting from the child process of a fork from a spawned thread

2009-09-01 Thread Reid Kleckner
On Tue, Sep 1, 2009 at 2:58 PM, "Martin v. Löwis" wrote: >> On one hand, you may not want to call the user's atexit handlers >> multiple times from different processes if they have externally >> visible effects.  On the other hand, people seem to assume that >> Py_Finalize will be called at process

Re: [Python-Dev] Whether to call Py_Finalize when exiting from the child process of a fork from a spawned thread

2009-09-01 Thread Martin v. Löwis
> On one hand, you may not want to call the user's atexit handlers > multiple times from different processes if they have externally > visible effects. On the other hand, people seem to assume that > Py_Finalize will be called at process exit to do various cleanups. On > the third hand, maybe Pyt

Re: [Python-Dev] why different between staticmethod and classmethod on non-callable object?

2009-09-01 Thread Brett Cannon
On Tue, Sep 1, 2009 at 07:21, Benjamin Peterson wrote: > 2009/8/31 xiaobing jiang : >> My idea is: here, the two functions (or maybe classes) should have the >> same behavior). >> so is this a bug or something I missing ? > > I think they should both not check their arguments in __init__ to > allow

[Python-Dev] Whether to call Py_Finalize when exiting from the child process of a fork from a spawned thread

2009-09-01 Thread Reid Kleckner
Hi all, I'm working on http://bugs.python.org/issue6642 for unladen swallow (because it happens to bite us in a weird way), and Jeff Yasskin told me to ask python-dev what the proper behavior should be at exit from the child process of a fork from a spawned thread. Right now, it seems that there

Re: [Python-Dev] default of returning None hurts performance?

2009-09-01 Thread Jake McGuire
On Mon, Aug 31, 2009 at 5:01 PM, Greg Ewing wrote: > Antoine Pitrou wrote: > > Did your coworker run any timings instead of basing his assumptions on >> bytecode >> size? >> > > In any case, what are you suggesting -- that the last value > returned by a function call in the body should be the > d

Re: [Python-Dev] [OT] implicit return values

2009-09-01 Thread Xavier Morel
On 1 Sep 2009, at 15:25 , Antoine Pitrou wrote: Le mardi 01 septembre 2009 à 15:09 +0200, Xavier Morel a écrit : "We" are not Erlang, Smalltalk, OCaml or Haskell either, sadly. Well, feel free to prefer an unreadable language if you want :) Smalltalk or Haskell are hardly inherently unreadable.

Re: [Python-Dev] default of returning None hurts performance?

2009-09-01 Thread Raymond Hettinger
I fail to understand this crude logic. If a function contains any looping (C or otherwise) or does much in the way of meaningful work, then it's unlikely that the single POP_TOP associated with an implied "return None" is taking much of the total runtime. Raymond

Re: [Python-Dev] why different between staticmethod and classmethod on non-callable object?

2009-09-01 Thread Benjamin Peterson
2009/8/31 xiaobing jiang : > My idea is: here, the two functions (or maybe classes) should have the > same behavior). > so is this a bug or something I missing ? I think they should both not check their arguments in __init__ to allow for duck typing. -- Regards, Benjamin __

Re: [Python-Dev] default of returning None hurts performance?

2009-09-01 Thread Xavier Morel
On 1 Sep 2009, at 02:01 , Greg Ewing wrote: I don't think the unpredictability that would introduce would be a good idea. I fail to grasp the unpredictability of "the last expression evaluated in the body of a function is its return value". It couldn't work in Python because statements aren't

Re: [Python-Dev] default of returning None hurts performance?

2009-09-01 Thread Xavier Morel
On 1 Sep 2009, at 03:03 , Gregory P. Smith wrote: On Mon, Aug 31, 2009 at 5:01 PM, Greg Ewing >wrote: Antoine Pitrou wrote: Did your coworker run any timings instead of basing his assumptions on bytecode size? In any case, what are you suggesting -- that the last value returned by a fu

Re: [Python-Dev] [OT] implicit return values

2009-09-01 Thread Antoine Pitrou
Le mardi 01 septembre 2009 à 15:09 +0200, Xavier Morel a écrit : > "We" are not Erlang, Smalltalk, OCaml or Haskell either, sadly. Well, feel free to prefer an unreadable language if you want :) Having implicit return values is certainly not something which follows Python's design principles. Even

Re: [Python-Dev] default of returning None hurts performance?

2009-09-01 Thread Steven D'Aprano
On Tue, 1 Sep 2009 05:51:49 pm Scott Dial wrote: > Raymond Hettinger wrote: > >> I was just wondering if a bytecode for a superinstruction of the > >> common sequence: > >> > >> 6 POP_TOP > >> 7 LOAD_CONST 0 (None) > >> 10 RETURN_VALUE > >> > >> might be worth it. > > > > [Collin Winter] > > > >> I

Re: [Python-Dev] default of returning None hurts performance?

2009-09-01 Thread Scott Dial
Raymond Hettinger wrote: >> I was just wondering if a bytecode for a superinstruction of the common >> sequence: >> >> 6 POP_TOP >> 7 LOAD_CONST 0 (None) >> 10 RETURN_VALUE >> >> might be worth it. > > [Collin Winter] >> I doubt it. You'd save a bit of stack manipulation, but since this >> will on

Re: [Python-Dev] runpy.py

2009-09-01 Thread Nick Coghlan
Brett Cannon wrote: > On Mon, Aug 31, 2009 at 06:36, Nick Coghlan wrote: >> That said, while actually ditching the C code might cause an argument, >> expanding runpy with Python equivalents of the C level functionality >> (i.e. run script by name, run directory/zipfile by name, '-c' switch, >> and

Re: [Python-Dev] how important is setting co_filename for a module being imported to what __file__ is set to?

2009-09-01 Thread Nick Coghlan
Fred Drake wrote: > Every time I've been bitten by the wrong co_filename values (usually > from tracebacks), changing the way marshal creates code objects to use a > values passed in has been the thing that made the most sense to me. > > The feature request that's involved here, getting correct co

Re: [Python-Dev] default of returning None hurts performance?

2009-09-01 Thread Scott Dial
Raymond Hettinger wrote: >> I was just wondering if a bytecode for a superinstruction of the common >> sequence: >> >> 6 POP_TOP >> 7 LOAD_CONST 0 (None) >> 10 RETURN_VALUE >> >> might be worth it. > > [Collin Winter] >> I doubt it. You'd save a bit of stack manipulation, but since this >> will on