
On 1/11/21 6:34 PM, Paul Bryan wrote:
a.__annotations__ = o assert a.__annotations__ == o
Would that assert fail? It depends on what type(o) is, which is surprising.
Equally surprising?:
a.__co_annotations__ = o a.__annotations__ assert a.__co_annotations__ == o
Well, since you asked, no. It's a good point, but I think my example is a touch more "surprising". In my example, a.__annotations__ has two different True values; in yours, a.__co_annotations__ goes from True to False. It's acting more like a cache. Also consider: if you set o.__annotations__ to a function, what if you want to examine the function later? What if you want to examine the function built by Python? def enhance_annotations(co_annotations): def enhance(): d = co_annotations() d['extra'] = ... return d o.__co_annotations__ = enhance_annotations(o.__co_annotations__) Finally, it's just a code smell to have one attribute support such a bewildering variety of types. Of course, this /works,/ but it's bad hygiene to store such violently different types in what is ostensibly the same attribute. Cheers, //arry/