Readit News logoReadit News
zahlman commented on A “frozen” dictionary for Python   lwn.net/SubscriberLink/10... · Posted by u/jwilk
mrweasel · 3 days ago
Agreed. The only reason to make them sorted is because people would wrongly assume that they where. You can argue that a programming language should not have unexpected behaviors, and apparently unsorted dictionary keys where a surprise to many, on the other hand I feel like it's a failure of education.

The problem was that assuming that keys would be sorted was frequently true, but not guaranteed. An alternative solution would have been to randomize them more, but that would probably break a lot of old code. Sorting the keys makes no difference if you don't expect them to be, but it will now be a greater surprise if you switch language.

zahlman · 8 hours ago
"sorted" and "ordered" mean very different things in this context.

And the reason we have ordered dict keys now is because it's trivial with the new compact structure (the actual hash table contains indices to an auxiliary array, which can just be appended to with every insertion). It has nothing to do with any randomization of the hashing process.

zahlman commented on A “frozen” dictionary for Python   lwn.net/SubscriberLink/10... · Posted by u/jwilk
xamuel · 3 days ago
That argument would apply to sets too, and yet frozenset is builtin.
zahlman · 8 hours ago
The elements of a frozenset need to be hashable, too.
zahlman commented on A “frozen” dictionary for Python   lwn.net/SubscriberLink/10... · Posted by u/jwilk
xamuel · 3 days ago
This subject always seems to get bogged down in discussions about ordered vs. unordered keys, which to me seems totally irrelevant. No-one seems to mention the glaring shortcoming which is that, since dictionary keys are required to be hashable, Python has the bizarre situation where dicts cannot be dict keys, as in...

{{'foo': 'bar'}: 1, {3:4, 5:6}: 7}

...and there is no reasonable builtin way to get around this!

You may ask: "Why on earth would you ever want a dictionary with dictionaries for its keys?"

More generally, sometimes you have an array, and for whatever reason, it is convenient to use its members as keys. Sometimes, the array in question happens to be an array of dicts. Bang, suddenly it's impossible to use said array's elements as keys! I'm not sure what infuriates me more: said impossibility, or the python community's collective attitude that "that never happens or is needed, therefore no frozendict for you"

zahlman · 8 hours ago
> the glaring shortcoming which is that, since dictionary keys are required to be hashable, Python has the bizarre situation where dicts cannot be dict keys

There is nothing at all bizarre or unexpected about this. Mutable objects should not be expected to be valid keys for a hash-based mapping — because the entire point of that data structure is to look things up by a hash value that doesn't change, but mutating an object in general changes what its hash should be.

Besides which, looking things up in such a dictionary is awkward.

> More generally, sometimes you have an array, and for whatever reason, it is convenient to use its members as keys.

We call them lists, unless you're talking about e.g. Numpy arrays with a `dtype` of `object` or something. I can't think of ever being in the situation you describe, but if the point is that your keys are drawn from the list contents, you could just use the list index as a key. Or just store key-value tuples. It would help if you could point at an actual project where you encountered the problem.

zahlman commented on PythoC: A new way to generate C code from Python   infoworld.com/article/410... · Posted by u/pm2222
zahlman · 9 hours ago
> PythoC doesn’t yet have a mechanism for re-using compiled code when it’s called from Python, the way Cython does.

> At first this seems like a pretty big limitation. But it’s actually the point: You can use PythoC as a code generation system for C programs that run independently, rather than C modules imported into Python.

I have a feeling this model isn't going to be very popular, and they'd be much better off with a way to reuse the compilation result.

> One possibility is that it could integrate more closely with Python at runtime. For instance, a @cached decorator could compile modules once, ahead of time, and then re-use the compiled modules when they’re called from within Python, instead of being recompiled at each run.

Yeah, pretty much what I was thinking. The @compile-decorated function is usable from Python, so the necessary binding logic is already implemented; so surely the decorator could just check a cache to see if the compiled equivalent is already available.

It seems like a powerful and flexible idea overall, though. The toy examples are probably not doing a great job of showcasing what's possible this way.

zahlman commented on Pre-PEP: Rust for CPython   discuss.python.org/t/pre-... · Posted by u/BiteCode_dev
pjmlp · a day ago
I wasn't happy with yet another RIR, however apparently plenty folks of core team, including Guido, seem to be up for it.
zahlman · 9 hours ago
The proposal is a long way off from a complete rewrite. It would be many years before end users were even compelled to use a Rust-required CPython to have a supported version.
zahlman commented on Tell HN: The Python Software Foundation is now showing banner ads    · Posted by u/inesranzo
zahlman · 10 hours ago
> I don't understand why the PSF is begging me to donate by showing an intrusive (and borderline manipulative) banner ad disrupting my reading flow.

Putting aside matters of real-world politics and "culture war", my main objection to the PSF is their funding allocation. Almost all core developers are volunteering (aside from a couple of "developer-in-residence" positions; we're talking about on the order of a hundred volunteers here), and presumably not all of them have high-paying day jobs at major tech companies (although certainly a lot of the more easily recognized names do). Many more administrative staff are paid, not obscenely much but certainly more than zero.

And then the lion's share of the rest of the budget goes to operating PyCon US. I guess (reviewing the financial reports) this is profitable for them, given that their "operating service revenue" must be pretty close to 100% from that. But it's hard for me to imagine why people would pay those prices to see talks that will later be available on YouTube (and which could almost universally do with a lot of editing) unless they're really there to meet people in person. Meanwhile other meetups worldwide get a pittance in support. I know that there are grants awarded specifically to enable the less privileged to attend PyCon, but the whole thing still strikes me as rather elitist.

But on the other hand, I do sympathize with the Python project (not so much the Foundation) being severely underfunded for what it is. When I see the Wikipedia banners I'm disgusted because I know the Wikimedia Foundation is already, by non-profit "do good things on the Internet" foundation standards, absolutely drowning in cash. But the PSF's existing dues and contributions wouldn't even cover the costs of the "Packaging Work Group / Infrastructure / Other" category in the 2024 breakdown. And that is without considering Fastly's generous in-kind donation of bandwidth (which AIUI is in the exabyte/year range now). The PSF really have not "been paid massively", notwithstanding estimates of the value of that in-kind donation. You can see the numbers for yourself (https://www.python.org/psf/annual-report/2024/).

Deleted Comment

zahlman commented on A “frozen” dictionary for Python   lwn.net/SubscriberLink/10... · Posted by u/jwilk
FreakLegion · 2 days ago
> I've felt like frozendict was missing for a long time, though.

Type the dict as a mapping when you want immutability:

  x: Mapping[int, int] = {1: 1}

  x[1] = 2  # Unsupported target for indexed assignment ("Mapping[int, int]").
The only problem I've seen with this is:

  y = {}
  y[x] = 0  # Mypy thinks this is fine. Mapping is hashable, after all!
The issue here is less that dict isn't hashable than that Mapping is, though.

zahlman · 2 days ago
This is because the ABC system is defined such that MutableMapping is a subtype of Mapping. Which mostly makes sense, except that if we suppose there exist Mappings that aren't MutableMappings (such that it makes sense to recognize two separate concepts in the first place), then Mapping should be hashable, because immutable things generally should be hashable. Conceptually, making something mutable adds a bunch of mutation methods, but it also ought to take away hashing. So Liskov frowns regardless.
zahlman commented on Deprecate like you mean it   entropicthoughts.com/depr... · Posted by u/todsacerdoti
oivey · 2 days ago
No, it does not: https://numpy.org/doc/stable/dev/depending_on_numpy.html.

> It is important to know that NumPy, like Python itself and most other well known scientific Python projects, does not use semantic versioning. Instead, backwards incompatible API changes require deprecation warnings for at least two releases.

zahlman · 2 days ago
Have they made breaking changes to the ABI in other versions?
zahlman commented on Programmers and software developers lost the plot on naming their tools   larr.net/p/namings.html... · Posted by u/todsacerdoti
parpfish · 2 days ago
I’ve been told multiple times in multiple jobs that I’m good at naming things, and I love whimsical names. A couple rules I’ve internalized are:

- if it’s hard to name, that’s a good sign that you haven’t clearly delineated use case or set of responsibilities for the thing

- best case for a name is that it’s weird and whimsical on first encounter. Then when somebody tells you the meaning/backstory for the name it reveals some deeper meaning/history that makes it really memorable and cements it in your mind

- the single best tech naming thing I’ve encountered (I didn’t come up with it) was the A/B testing team at Spotify naming themselves “ABBA”

zahlman · 2 days ago
> I’ve been told multiple times in multiple jobs that I’m good at naming things, and I love whimsical names.

As long as you're naming products and features, rather than variables.

u/zahlman

KarmaCake day5196August 18, 2024View Original