A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-list/2001-April/089465.html below:

Idiom gone, or did it really ever exist? () is ()

Idiom gone, or did it really ever exist? () is ()Mike C. Fletcher mcfletch at home.com
Tue Apr 17 23:59:43 EDT 2001
Over the years, I've occasionally used this idiom:

NULLARGUMENT = ()

def someFunctionOrMethod  (argument = NULLARGUMENT ):
    if argument is NULLARGUMENT:
        doSomething()
    else:
        doSomethingElse()

That is, I was attempting to distinguish between a call where argument is
passed a NULL tuple and a call where argument is passed nothing at all.
When I was working on unit tests for my current piece of code, however, I
discovered that this no longer works (Python 1.5.2).  No idea for how long
it hasn't worked.  Now, of course, I could have used:

class NULL: pass
NULLARGUMENT = NULL() # a particular instance

or

NULLARGUMENT = NULL # use the class itself

or

NULLARGUMENT = []

or I could've used an approach where I used *arguments and **namedarguments
to determine whether the argument was really passed.  There are all sorts of
other ways to do this.  Apparently optimisation has come to the tuples of
the world, so using tuple identities is now a no-no.

All those who have used null-tuple identities should now go and fix their
code.
Mike

__________________________________
 Mike C. Fletcher
 Designer, VR Plumber
 http://members.home.com/mcfletch



More information about the Python-list mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4