This has been suggested before, if you are serious about pursuing the idea you should search the archives both here and on the Python-Ideas mailing list.
There are three parts to this:
- Is it true that
{}
as an empty set is more intuitive than {}
as an empty dict?
- Can we introduce
{:}
as syntax for an empty dict?
- Can we change
{}
so it creates a set instead of a dict?
Part 1 is plausible but not proven. It seems to me that dicts are far more important, and common, than sets.
Part 2 is certainly possible. We could introduce {:}
as syntax for empty dicts.
But part 3 is where things get very hard. Python is a 30+ year old language with tens of thousands of users, tens of millions of lines of code, thousands of blog posts, Stackoverflow answers, tutorials etc. We have to take backwards compatibility really seriously. Changing the meaning of {}
is not an easy thing to do, it is much harder than
That would change the meaning of strings containing “{}”, including f-strings and format strings. It would make hundreds of books, tutorials, blog posts etc obsolete and wrong, causing confusion to anyone reading them.
And who is going to do that find-and-replace? You? We are forcing thousands of developers to change their code, and I guarantee that some code will be missed.
Very young languages with only a few users can make radical changes at the drop of a hat. But for a mature language like Python, such a backwards-compatibility breaking change is a big deal.
We have a process for such changes, possibly involving a __future__
import. Even if we don’t do that, there would have to be a long depreciation period, probably three releases if not more, during which any attempt to use {}
will give a DepreciationWarning.
With that amount of pain and breakage involved in the change-over, the benefit would need to be corresponding bigger. And frankly, the benefit is pretty small.
Sad to say, I think that this is a missed opportunity. We should have made this change as part of the Python 2 to 3 transition. But we didn’t, and now the benefit is probably too small for us to ever make that change worth the pain and effort.