[Python-ideas] Make obj[] valid syntax?
Thomas Heller
theller at ctypes.org
Wed Nov 14 19:29:52 CET 2007
I'm not sure if this is a good idea or not, but - hey - this
is python.ideas ;-)
The following statements currently raise a SyntaxError:
obj[] = something
x = obj[]
I propose to make these statements valid syntax.
'obj[]' should behave like 'obj[()]' does:
Call __getitem__ or __setitem__ with an empty tuple.
My use case is in a COM library (comtypes).
Some COM properties require one or more arguments; this is
not a problem since one could write
obj.prop[1, 2, 3]
Sometimes, however, arguments are optional. Unfortunately
one has to write
obj.prop[()]
to pass an empty tuple to __getitem__ or __setitem__,
which looks strange imo.
Comments?
Thomas
More information about the Python-ideas
mailing list