
On Mon, Nov 28, 2022 at 6:45 PM Steven D'Aprano <steve@pearwood.info> wrote:
On Tue, Nov 29, 2022 at 01:34:54PM +1300, Greg Ewing wrote:
I got the impression that there were some internal language reasons to want stable dicts, e.g. so that the class dict passed to __prepare__ preserves the order in which names are assigned in the class body. Are there any such use cases for stable sets?
Some people wanted order preserving kwargs, I think for web frameworks. There was even a discussion for a while about using OrderedDict for kwargs and leaving dicts unordered.
See https://peps.python.org/pep-0468/ (kwargs) and https://peps.python.org/pep-0520/ (class definition body). I re-implemented OrderedDict in C for this purpose. Literally right after I had finished that, Inada-san showed up with his compact dict implementation. Many of us were at the first core sprint at the time and there was a lot of excitement about compact dict. It was merged right away (for 3.6) and there was quick agreement that we could depend on dict insertion ordering internally (for a variety of use cases, IIRC). Thus, suddenly both my PEPs were effectively implemented, so we marked them as approved and moved on. FWIW, making the insertion ordering an official part of the language happened relatively soon afterward, though for 3.7, not 3.6. [1] I'm pretty sure there's a python-dev thread about that. The stdtypes docs were updated [2] soon after, and we finally got around to updating the language [3] a couple years later. -eric [1] https://docs.python.org/3/whatsnew/3.7.html#summary-release-highlights [2] https://bugs.python.org/issue33609 [3] https://bugs.python.org/issue39879