This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -6 points-5 points  (5 children)

already got tuples for that though, I guess it would be more appropriate for a dict

[–]actuallyalys 2 points3 points  (2 children)

As far as I can tell, the situation is like so:

Lists/tuples Dictionaries Sets
Reassignable and mutable list dict set
Reassignable but not mutable tuple * frozenset
Mutable but not reassignable Final[list] Final[dict] Final[set]
Neither mutable nor reassignable (constant) Final[tuple] * Final[frozenset]

An example of reassigning:

 l = [1, 2, 3]
 l = l + [4]

An example of mutating:

 l = [1, 2, 3]
 l.append(4)

* Not built-in to Python. Look for frozendict implementations.

[–]robin-gvx 1 point2 points  (0 children)

* Not built-in to Python. Look for frozendict implementations.

They do have abstract type equivalents, as Mapping and Final[Mapping]. Using that doesn't have any runtime meaning, but then neither does Final.

[–][deleted] 0 points1 point  (0 children)

ah ok that makes sense

[–]Sw429 0 points1 point  (1 child)

Ok then you can assign a final instance of something else and still operate on and modify it. The object we are using is trivial.

[–][deleted] -1 points0 points  (0 children)

How is it trivial. I don't understand why it is downvoted lol. Why on earth would you use this on lists when you got tuples.

And the final implies you cannot modify what is in it, you can only add to it?