__iadd__ and fellows missing (Python 2.2)

Steve Holden sholden at holdenweb.com
Mon Apr 15 13:49:03 EDT 2002


"Mike C. Fletcher" <mcfletch at rogers.com> wrote ...
> Rather than confuse Tim further with abstract samples of where I want to
> define a "NULL" default argument, here's a particular example of where
> the "NULL pattern" I've described is used:
>
> NULL = []
>
Note that this does indeed cause the NULL variable to refer to a specific
instance of the empty list (and a tuple would be acceptable here rather than
a list).

> class BasicProperty (property):
> ...
> def __init__( self, name, documentation = "", bounds = (),
> defaultValue=NULL, defaultFunction=NULL ):
> ...
> if defaultValue is not NULL:
> self.defaultValue = defaultValue
> elif defaultFunction is not NULL:
> self.defaultFunction = defaultFunction
>
[sorry, OutOfLuck Express doesn't see your tabs]

The only situation this will not help you with is if you need to distinguish
between the following calls:

    BasicProperty("One")

    BasicProperty("One", defaultValue=NULL)
and
    BasicProperty("One", defaultValue=())

> Now, I want to store/define defaultValue only if defaultValue is
> explicitly specified (same for defaultFunction).
>
The situation where you do not provide an argument value is guiaranteed to
work as long as you don't rebind the NULL variable. I believe the first and
second cases are entirely equivalent under that assumption.

The third case is trickier, however, as there is no guarantee that the
implementation won't optimize, so it is permissible for different
implementations to use either the same or different lists (or tuples).

> I _could_ (as you suggest) use namedarguments and require that the user
> name the arguments explicitly.  However, when I do that, the
> defaultValue and defaultFunction arguments don't show up in the user's
> call-tip window using Python IDEs.  (And I dislike the aesthetics of
> using **namedarguments when all acceptable names are known anyway :) ).
>
I agree that it's clunkier, but that's the timbot for you: always suggesting
things that work, no matter how inconvenient this is for us mere mortals :-)

> As for the "designed purpose of default arguments" :) .  I see the value
> "no value/not specified" as a perfectly suitable default value.  Sure,
> it may offend your sensibilities, but when has that stopped me in the
> past ;) .
>
Apparently never, if the above is typical of your disregard for the bot's
feelings.

regards
 Steve







More information about the Python-list mailing list