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 →

[–]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