▲ | ansgri 7 months ago | ||||||||||||||||||||||
Why? I thought one should prefer immutability. As for typed dicts.. yes, I’m mostly stuck on old python versions, nice reminder. | |||||||||||||||||||||||
▲ | int_19h 7 months ago | parent | next [-] | ||||||||||||||||||||||
In general, preferring immutability is great. In Python specifically, it can be hard to pull off given that e.g. something as basic as dict does not have a standard immutable equivalent. You inevitably have to rely on conventions - basically saying "this is supposed to be immutable" rather than enforcing it. | |||||||||||||||||||||||
▲ | maleldil 7 months ago | parent | prev | next [-] | ||||||||||||||||||||||
You can use TypedDict from `typing_extensions` if your version doesn't have it. You can use a lot of the newer stuff from there, too, especially if you enable `__future__.annotations`. How old is your Python, though? TypedDict is from 3.8. That was 5 years ago. | |||||||||||||||||||||||
▲ | throwaway2037 7 months ago | parent | prev [-] | ||||||||||||||||||||||
You can use:
to create an immutable data class. | |||||||||||||||||||||||
|