And thus, it’s better to lay down that the order is not guaranteed to be preserved then. As mentioned, we already do it for JSON (that is, guarantee something that the specs don’t). We can also do it for tomllib (if this makes kind of implementation details makes sense). I don’t know if JSON explicitly says that there is no guarantee though. But since TOML explicitly says it, then it’s better to also restate it so that people don’t make wrong assumptions.
EDIT: maybe I wasn’t clear in my previous posts but I’m neither for nor against documenting the key ordering. We can say that it’s an implementation detail and not guaranteed by the specs, or simply state that there is no key ordering guarantees like the specs. At least, I want the docs to be clear on that (as it’s burried quite well in TOML specs).
tomllib diverging from what other languages guarantee would create a a situation where if someone relies on that divergence, they can’t use toml as a cross-language format
Honesly, it’s not really an issue if we clearly document that it’s what Python offers and not what the specs guarantee. The question is whether to document it loudly as an implementation detail, or state that there is no table key ordering that is guaranteed.
If we want to prevent future complains, we can just restate the TOML docs about ordering guarantees (we already say that we return a dict and it’s easy to assume that your TOML document will be simply parsed as a dicts with multiple levels and thus one could expect the implementation to preserve insertion order).
For JSON, I think we mentioned the order preserving because of the sort_keys=False parameter (so that users understand that they can also force another order).
I don’t think that tomllib shouldn’t guarantee anything TOML doesn’t,
Sometimes, the stdlib offers more than just plain specs. For instance, all the HTTP-related modules are meant to be really RFC compliant, but sometimes they either restrict or offer more. So it can guarantee more things than what is expected (usually it’s behind a gate though).
I’d give here is that tools like uv and ruff are written in rust, and are intended to be able to be used as drop-in replacements for other tools that read pyproject.toml adding that constraint after the fact now also constrains drop-in replacements
Strictly speaking, having an additional constraint doesn’t make your tool less usable. If you decide to rely on something that is guaranteed by the implementation but not by the specs, it’s the user’s decision. And it would be wrong to assume that a simple drop-in replacement would be correct. We are still compliant with the specs strictly speaking (fixing an ordering in the implementation doesn’t conflict with “there is no order guaranteed”).
To summarize: I’m ok for restating the “no ordering is guaranteed”. If we once decide to extend the interface and change the behavior, it’s also fine (e.g., adding an “sort_keys” parameter in tomllib.load()), as long as we are clear on this “extension”.