[Python-Dev] Got None. Maybe Some?

Michael Chermside mcherm at mcherm.com
Mon Dec 22 08:33:45 EST 2003

  [Josiah proposes a Some object to be the counterpart of None]

  [Guido seems reluctant]

Josiah: I have a counterproposal. The good news is, it's REALLY easy -- you
won't need a PEP, and I am sure that you'll get no objections from anyone
on this list. And it'll provide you with a "Some" object that acts like
you describe (except the one mention you made of "Some == not None"...
that one's a bad idea since right now "True == not None").

Here's the idea: Create a file called "Some.py":

-------- Some.py ------------
class _SomeType(object):
    def __lt__(self, other):
        return False # never less than anything
    def __le__(self, other):
        if other is Some:
            return True # equal to itself
            return False # less than anything else
    def __gt__(self, other):
        if other is Some:
            return False # equal to itself
            return True # greater than anything else
    def __ge__(self, other):
        return True # greater than or equal to anything
    def __repr__(self):
        return 'Some'

Some = _SomeType() # singleton instance
---------- end --------------

Place this in your python path, then add this line to the top of your

"from Some import Some".

If you really want to, you could put code in your site.py file so
that you don't even need this import line, but I think in the long
run you'll prefer using the import line.

I think that this meets your expectations (if I understood them
properly), and if not, it can probably be adjusted so that it does.
The one thing it doesn't do is that it isn't part of the Standard
Library. But that doesn't mean it can't be part of YOUR standard
library... something you use all the time all over the place. I
think that most people on this list (myself included) would say
that the uses of this object are sufficiently esoteric and the
naming of it is sufficiently quirky that they wouldn't want it in
the language itself, but *everyone* here would stand up for your
right to create and use such an object yourself... something which
would never be possible in (for instance) Java.

Once-we've-got-Some-perhaps-we-should-consider-a-builtin-Milk lly yours,

-- Michael Chermside

More information about the Python-Dev mailing list