Re: namespace issue, Python vs numpy min/max problem

2010-11-14 Thread Robert Kern

On 2010-11-14 17:37 , Gregory Ewing wrote:

Steven D'Aprano wrote:

It only becomes your problem if you have advised people that the right way to
use your module is with import *.


And if you're advising people to do that, it would be an
extremely good idea to give your functions different names
so that they don't conflict with the builtin min and max.


And we (the numpy devs) explicitly advise people *against* that.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list


Re: namespace issue, Python vs numpy min/max problem

2010-11-14 Thread Gregory Ewing

Steven D'Aprano wrote:
It 
only becomes your problem if you have advised people that the right way 
to use your module is with import *.


And if you're advising people to do that, it would be an
extremely good idea to give your functions different names
so that they don't conflict with the builtin min and max.

--
Greg
--
http://mail.python.org/mailman/listinfo/python-list


Re: namespace issue, Python vs numpy min/max problem

2010-11-13 Thread Steven D'Aprano
On Sat, 13 Nov 2010 11:41:09 -0800, dmitrey wrote:

> hi all,
> I have the following problem:
> I have overloaded "max" function in my module (FuncDesigner); it works
> like following:
> if some data in arguments is of type "oofun" then my function works,
> elseware numpy.max() is used.
> 
> Now the problem:
> suppose someone writes
> from FuncDesigner import *
> ...
> a = max(0,1)
> 
> so it calls FuncDesigner, it calls numpy.max and result is 0 (because in
> numpy it means "max of array with single element 0 along 1st axis").
> But if user has not imported numpy then he expected calling ordinary
> Python max and thus result to be "1".

That's not your problem, that's the caller's problem. He shouldn't be 
calling import * unless he wants to import everything in your module 
directly into his namespace.

If the caller said to you:

"After executing len = x, I can't access the built-in len function any 
more, can you change x so that it magically tells when I want the built-
in behaviour and does that?"

you'd probably tell him to get lost. Doing import * is no different. It 
only becomes your problem if you have advised people that the right way 
to use your module is with import *.


> Is there any way to get rid of the problem (somehow automatically
> determine which func should be used - numpy or Python max)? The same
> issue with "min", but they are equivalent, of course.

Automatically? No.

-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: namespace issue, Python vs numpy min/max problem

2010-11-13 Thread Terry Reedy

On 11/13/2010 2:41 PM, dmitrey wrote:

hi all,
I have the following problem:
I have overloaded "max" function in my module (FuncDesigner); it works
like following:
if some data in arguments is of type "oofun" then my function works,
elseware numpy.max() is used.

Now the problem:
suppose someone writes
from FuncDesigner import *


Noone should do that unless your module is **explicitly** designed to be 
*-imported and you docuement that so that they know it is OK.


Now you know why * import is generally discouraged ;-).

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: namespace issue, Python vs numpy min/max problem

2010-11-13 Thread Ben James

On 13/11/2010 19:55, dmitrey wrote:

Well, I think I have found an appropriate solution.
Regards, D.


Hi Dmitrey,

Would you mind briefly describing your solution?

Thanks,
Ben
--
http://mail.python.org/mailman/listinfo/python-list


Re: namespace issue, Python vs numpy min/max problem

2010-11-13 Thread dmitrey
Well, I think I have found an appropriate solution.
Regards, D.
-- 
http://mail.python.org/mailman/listinfo/python-list


namespace issue, Python vs numpy min/max problem

2010-11-13 Thread dmitrey
hi all,
I have the following problem:
I have overloaded "max" function in my module (FuncDesigner); it works
like following:
if some data in arguments is of type "oofun" then my function works,
elseware numpy.max() is used.

Now the problem:
suppose someone writes
from FuncDesigner import *
...
a = max(0,1)

so it calls FuncDesigner, it calls numpy.max and result is 0 (because
in numpy it means "max of array with single element 0 along 1st
axis").
But if user has not imported numpy then he expected calling ordinary
Python max and thus result to be "1".

Is there any way to get rid of the problem (somehow automatically
determine which func should be used - numpy or Python max)? The same
issue with "min", but they are equivalent, of course.
-- 
http://mail.python.org/mailman/listinfo/python-list