Re: Automatic binding of **kwargs to variables



bonono@xxxxxxxxx <bonono@xxxxxxxxx> wrote:

> Don't know about this particular case but sometimes, I don't want to
> have a default argument value. That is, argument not there is different
> from argument = None. Though in general, I prefer the None as special
> meaning coding style. But even python's builtin function prefers to
> distinguish between "not there" and None.

the canonical idiom when you need such distinction is:

_not_there = object()
def foo(bar=_not_there, baz=_not_there, bap=_not_there):
if bar is _not_there: ...

Other unique objects can be substituted for the 'sentinel', but I prefer
an empty "object()" because it has no other possible meaning except that
of a distinguishable, identifiable sentinel. IOW, you could set the
_not_there name to [] or {} or many other things, but that could be
slightly confusing for the reader (since the other things might have
other meanings and purposes) while 'object()' shouldn't be.

At any rate, the complicated code I was commenting on did treat absent
expected arguments exactly the same way as arguments passed as None,
which is also a frequent use case, so this further level of refinement
was apparently not warranted ("use only as much power as you need" is a
programming principle that tends to promote simplicity, and therefore,
in many cases, is well worth adhering to).


Alex
.



Relevant Pages

  • Re: Why choose a paragraph element for a paragraph?
    ... not exactly news to anyone! ... appreciate this distinction is big indeed. ... So would you say something like that mind is meaning and brain is ... they are part of the world outside language. ...
    (alt.html)
  • Re: "I just came back" vs. "Ive just come back"
    ... Many European languages make past tenses with the ... English foreign learners find difficult; this distinction causes ... Though this "perfective" meaning is often ...
    (alt.usage.english)
  • =?iso-8859-1?q?Re:_Von_Gleichheit_und_Identit=E4t?=
    ... Between attributes and properties I make no distinction, ... Carnap schreibt in "Meaning and Necessity": ... Im Sinne Gödels und Carnaps ist die Selbigkeit der Bedeutung von ...
    (de.sci.philosophie)
  • Re: Vector is to Point as ____ is to Angle?
    ... Scaling a point has a meaning. ... The distinction becomes quite obvious if we change the ... If the wind blows twice as fast, then the wind velocity vector ...
    (comp.programming)
  • Re: Common ancestor between man and ape
    ... definition of insect is identical with Insecta. ... over its history is going to hold any particular meaning in stasis. ... to us to warrant having a name that codifies that distinction. ... very often to name the various species of ape. ...
    (talk.origins)