[Python-3000] Dropping the parentheses after dict.keys?
Guido van Rossum
guido at python.org
Thu Dec 13 16:51:17 CET 2007
On Dec 13, 2007 1:24 AM, Noam Raphael <noamraph at gmail.com> wrote:
> Was it considered to drop the parentheses after "dict.keys()", to make
> it "dict.keys" (that is, to make it a property instead of a method
> with no arguments)? If it was, please forgive me - a few minutes of
> googling didn't find it.
Yes, it was considered, and rejected over a combination of backwards
compatibility and concerns that for some user-defined sequences it
would be expensive to compute and hence wrong to look like a mere
attribute. (The backwards compatibility concerns weren't merely of
breaking every line of code in existence -- we can fix that with the
2to3 tool; they were also over user expectations.)
> I now write (another?) ordered dict, and I thought that the easiest
> way to get the key with a given index would be "d.keys[5]". But it
> means that d.keys is a collection of keys, not a method - and why not?
>
> If backwards compatibility is a problem, we can make d.keys return the
> same object that d.keys() currently returns, and add to the dict_keys
> object a calling operation which raises a warning and returns itself.
>
> Of course, d.values and d.items are the same.
I'm not going to argue over your API choice for your own class, but I
have to take a firm stance regarding changes to the core language and
its builtins at this point. We had an extensive period for submission
and review of change proposals, which ended in April. While we are
still making some adjustments, we are limiting changes at this point
to what appears necessary based on actual experience with the alpha
releases, and your proposal doesn't fall in that category.
--
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000
mailing list