[Python-ideas] An Everything singleton
Steven D'Aprano
steve at pearwood.info
Tue Feb 18 22:57:23 CET 2014
On Tue, Feb 18, 2014 at 09:07:07PM +0200, Serhiy Storchaka wrote:
> This crazy idea is inspired by a discussing in Python-Dev which should
> be here.
>
> Currently we have a None singleton which representing nothing and raises
> an exception in almost all operations (except equality, etc). What about
> introducing its antonym, an Everything singleton (the name is
> discussable), which newer raises an exception in any operation, but
> returns consistent value?
>
> >>> Everything + 2
> 2
Here, your Everything value acts like the Null Object pattern.
> >>> Everything < 3
> True
Here, your Everything value acts like a Smallest object. But if you then
do Everything > 5, presumably you would want it to return True, so it
also acts like a Biggest object.
Why have Everything < 3 return True? Why not False?
> >>> Everything * 'foo'
> 'foo'
Here, your Everything object acts like an Identity object. But earlier
you had it acting like a Null object. How does the Everything object
decide whether it should behave as Null or Identity for a certain
operation? E.g. should 23**Everything return 1 or 23?
23 == Everything == 42
will presumably return True.
What should these things do?
some_dict.pop(Everything) # Is this the same as some_dict.clear()?
Everything & 42
'+'.join(['a', 'b', Everything, 'c'])
I don't think this idea is either useful or self-consistent.
--
Steven
More information about the Python-ideas
mailing list