On 10/26/21 5:22 PM, Bluenix wrote:
* Functions having the same signature share the same annotation tuple.
Is this true with code that have a mutable default?
[... examples deleted...]


You're confusing two disjoint concepts.

First of all, all your examples experiment with default values which are unrelated to their annotations.  None of your examples use or examine annotations.

Second, Inada-san was referring to the tuple of strings used to initialize the annotations for a function when PEP 583 (stringized annotations) is active.  This is a clever implementation tweak that first shipped with Python 3.10, which makes stringized annotations very efficient.  Since all the names and annotations are strings, rather than creating the dictionary at function binding time, they're stored in a tuple, and the dictionary is created on demand.  This tuple is a constant object, and marshalling a module automatically collapses duplicate constants into the same constant.  So identical PEP 583 annotation tuples are collapsed into the same tuple.  Very nice!


/arry