If you encounter the term Final, do you perceive it as indicating a constant object or a constant reference to a non-constant object?
In my scenario, I have a variable named registry
, which is a mapping of string keys to specialized objects.
registry: Final[dict[str, MyObject]] = {}
Now, the registry
variable is labeled as Final
. Can the objects stored in the registry change?
Based on how Python handles tuples, I believe that Final
denotes a constant reference to a non-constant object, i.e., I can add new MyObject
s to the registry. Is this correct?
Other programming languages use different approaches. For instance, Dart features both final and const keywords. In Dart, final implies that the variable registry
cannot be re-assigned to another object, while const signifies that the referenced object itself cannot be modified.
Does Python offer a mechanism distinguish between these two scenarios?