Re: [Python-Dev] Why is nb_inplace_power ternary?

2007-02-09 Thread Greg Ewing
Martin v. Löwis wrote:
> Greg Ewing schrieb:
> 
>> Might we want to add an in-place version of the 3-arg
>> pow() function one day?
> 
> What could the syntax for that be?

It wouldn't be a syntax, just a function, e.g.

ipow(x, n, 10)

> Also, it would break existing __ipow__ implementations
> that only receive two arguments

You could consider them broken already, since the
signature clearly implies that there could be a
third argument. The fact that it's not currently
used is no excuse. :-)

--
Greg
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Adding timeout option to httplib...connect()

2007-02-09 Thread Guido van Rossum
You're not helping, Skip. Can you spend a minute looking at urllib2
and seeing how the two variants of my proposal (pass to constructor
vs. pass to connect()) would impact on it?

--Guido

On 2/9/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> Guido> Didn't work for me, since my ap is a multi-threaded webserver and
> Guido> I only want one specific type of request to time out.
>
> Understood.
>
> Guido> I'm not going to change ftplib.py and all the others.
>
> Also understood.  This has, as far as I know, been the response of everybody
> who has encountered this problem before.  Most people are only interested in
> a single protocol (or module) and therefore aren't motivated to change/fix
> the other protocols which could benefit from timeouts.  After all, who
> really wants to update gopherlib?  So there is sits.
>
> Guido> I do think it's relevant to decide whether the timeout should be
> Guido> passed to the constructor or to the connect() method. I think it
> Guido> may be better to pass the timeout to the constructor.
>
> Another thing to consider is how this change might percolate up to
> urllib/urllib2.  (I advocate leaving urllib alone, but urllib2 should
> probably grow a timeout feature.)
>
> Skip
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Adding timeout option to httplib...connect()

2007-02-09 Thread skip

Guido> Didn't work for me, since my ap is a multi-threaded webserver and
Guido> I only want one specific type of request to time out.

Understood.

Guido> I'm not going to change ftplib.py and all the others.

Also understood.  This has, as far as I know, been the response of everybody
who has encountered this problem before.  Most people are only interested in
a single protocol (or module) and therefore aren't motivated to change/fix
the other protocols which could benefit from timeouts.  After all, who
really wants to update gopherlib?  So there is sits.

Guido> I do think it's relevant to decide whether the timeout should be
Guido> passed to the constructor or to the connect() method. I think it
Guido> may be better to pass the timeout to the constructor.

Another thing to consider is how this change might percolate up to
urllib/urllib2.  (I advocate leaving urllib alone, but urllib2 should
probably grow a timeout feature.)

Skip
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Adding timeout option to httplib...connect()

2007-02-09 Thread Guido van Rossum
On 2/9/07, Fred L. Drake, Jr. <[EMAIL PROTECTED]> wrote:
> On Friday 09 February 2007 08:52, [EMAIL PROTECTED] wrote:
>  > In principle it's probably a fine idea.  We should consider if it's
>  > possible to develop a uniform approach to timeouts for all the libraries
>  > that use sockets though.  Otherwise you run the risk of doing it in
>  > different ways for different libraries and having to make a (small, but
>  > annoying) semantic leap when going from, say, httplib to smtpllib or
>  > ftplib.
>
> Agreed.  In the meanwhile, there's socket.setdefaulttimeout(), which has
> proved quite useful.

Didn't work for me, since my ap is a multi-threaded webserver and I
only want one specific type of request to time out.

I'm not going to change ftplib.py and all the others.

I do think it's relevant to decide whether the timeout should be
passed to the constructor or to the connect() method. I think it may
be better to pass the timeout to the constructor.

>   -Fred
>
> --
> Fred L. Drake, Jr.   
>


-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Adding timeout option to httplib...connect()

2007-02-09 Thread Fred L. Drake, Jr.
On Friday 09 February 2007 08:52, [EMAIL PROTECTED] wrote:
 > In principle it's probably a fine idea.  We should consider if it's
 > possible to develop a uniform approach to timeouts for all the libraries
 > that use sockets though.  Otherwise you run the risk of doing it in
 > different ways for different libraries and having to make a (small, but
 > annoying) semantic leap when going from, say, httplib to smtpllib or
 > ftplib.

Agreed.  In the meanwhile, there's socket.setdefaulttimeout(), which has 
proved quite useful.


  -Fred

-- 
Fred L. Drake, Jr.   
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Why is nb_inplace_power ternary?

2007-02-09 Thread Brett Cannon
On 2/9/07, "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:
> Brett Cannon schrieb:
> > Seems reasonable to me.  Is the argument of None passed in
> > automatically somewhere?
>
> There are few callers of nb_inplace_power at all (AFAICT, only
> PyNumber_InPlacePower); in turn, PyNumber_InPlacePower is called
> with the implicit Py_None always:
> - ceval.c, for INPLACE_POWER (which is binary)
> - operator.ipow (which is also binary)
> - class.c, from bin_inplace_power, which in turn is called from
>instance_ipow if the instance's 3rd argument to
>nb_inplace_power is Py_None (if there is a non-None third
>argument, instance_ipow invokes __ipow__ with three arguments
>if __ipow__ is defined, else it invokes __pow__ with three
>arguments)
>
> The only case I could find where a third argument is non-None
> is when the builtin pow() is invoked, which then invokes nb_power
> (but not nb_inplace_power) with three arguments.
>

Well then explicitly ignoring the object makes sense to me.  While I
am personally fine with raising the exception, erring on the side of
caution as Raymond is suggesting wouldn't hurt either.

-Brett
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


[Python-Dev] Why is nb_inplace_power ternary?

2007-02-09 Thread Jim Jewett
Greg Ewing schrieb:
> Might we want to add an in-place version of the 3-arg
> pow() function one day? If so, leaving the third argument
> there could be useful.

"Martin v. Löwis" martin at v.loewis.de replied:
> What could the syntax for that be?

> Instead of writing

> x = pow(x, n, 10)

Either

x**= n % 10 # The **= changes the parse context, so that %
is no longer
# immediately evaluated
or

x**= (n, 10)  # exponentiation to a tuple isn't currently
defined, and it
# does show that both arguments are
part of the power
# expression -- but I'm not sure it
needs a 3-argument form
# instead of just unpacking the tuple itself.

-jJ
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Adding timeout option to httplib...connect()

2007-02-09 Thread skip

Guido> I recently needed to access an HTTP URL with a timeout. I ended
Guido> up monkey-patching httplib.HTTPConnection so that the connect()
Guido> method has an optional second paramer, timeout, defaulting to
Guido> None; if not None, a call to settimeout() is added right after
Guido> successful creation of the socket.

Guido> Does anybody else think this is a good idea?

In principle it's probably a fine idea.  We should consider if it's possible
to develop a uniform approach to timeouts for all the libraries that use
sockets though.  Otherwise you run the risk of doing it in different ways
for different libraries and having to make a (small, but annoying) semantic
leap when going from, say, httplib to smtpllib or ftplib.

Skip
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Adding timeout option to httplib...connect()

2007-02-09 Thread Martin v. Löwis
Guido van Rossum schrieb:
> I recently needed to access an HTTP URL with a timeout. I ended up
> monkey-patching httplib.HTTPConnection so that the connect() method
> has an optional second paramer, timeout, defaulting to None; if not
> None, a call to settimeout() is added right after successful creation
> of the socket.
> 
> Does anybody else think this is a good idea? (Personally I think this
> should've been done years ago. :-) Shall I check it into the head?

Please also consider #723312, which is more general, but also more
outdated.

Regards,
Martin
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Why is nb_inplace_power ternary?

2007-02-09 Thread Martin v. Löwis
Greg Ewing schrieb:
> Might we want to add an in-place version of the 3-arg
> pow() function one day? If so, leaving the third argument
> there could be useful.

What could the syntax for that be?

Instead of writing

x = pow(x, n, 10)

would you write

x pow n = 10

? or perhaps

x ** n = 10
or
x * n *= 10

Also, it would break existing __ipow__ implementations
that only receive two arguments (unless there would be
another __ method introduced).

Regards,
Martin

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Why is nb_inplace_power ternary?

2007-02-09 Thread Martin v. Löwis
Raymond Hettinger schrieb:
> That made sense, but my question was whether there would be benefit
> to making the change in the middle of a major release.  At worst, code 
> that is
> currently working due to undefined behavior will stop working.   I don't
> see any offsetting benefit.  ISTM that Py2.5 should be left as-is and that
> the full signature change be made in Py2.6.

I can't see "left as is" as an option, see #1648268 and #1653736. 
Apparently, there are platforms where the code traps when there
is a signature mismatch.

If raising an exception is unacceptable, I'd rather explicitly ignore
the extra argument, instead of ignoring it implicitly.

Regards,
Martin

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Why is nb_inplace_power ternary?

2007-02-09 Thread Martin v. Löwis
Brett Cannon schrieb:
> Seems reasonable to me.  Is the argument of None passed in
> automatically somewhere?  

There are few callers of nb_inplace_power at all (AFAICT, only
PyNumber_InPlacePower); in turn, PyNumber_InPlacePower is called
with the implicit Py_None always:
- ceval.c, for INPLACE_POWER (which is binary)
- operator.ipow (which is also binary)
- class.c, from bin_inplace_power, which in turn is called from
   instance_ipow if the instance's 3rd argument to
   nb_inplace_power is Py_None (if there is a non-None third
   argument, instance_ipow invokes __ipow__ with three arguments
   if __ipow__ is defined, else it invokes __pow__ with three
   arguments)

The only case I could find where a third argument is non-None
is when the builtin pow() is invoked, which then invokes nb_power
(but not nb_inplace_power) with three arguments.

Regards,
Martin

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com