[Python-ideas] Make obj[] valid syntax?

Guido van Rossum guido at python.org
Wed Nov 14 19:35:16 CET 2007


Why can't you use call syntax, i.e. obj.prop(1, 2, 3)?

On Nov 14, 2007 10:29 AM, Thomas Heller <theller at ctypes.org> wrote:
> 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
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>



-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-ideas mailing list