On 1/11/21 6:09 PM, Chris Angelico wrote:
On Tue, Jan 12, 2021 at 12:56 PM Larry Hastings firstname.lastname@example.org wrote:
It was a balancing act. Using an 64-byte empty dict per object with no defined annotations seems so wasteful. And anything short of an empty dict, you'd have to guard against. Current code already has to guard against "__annotations__ aren't set" anyway, so I figured the cost of migrating to checking a different condition would be small. And None is so cheap, and the guard is so easy:
Does it have to be mutable? If not, maybe there could be a singleton "immutable empty dict-like object", in the same way that an empty tuple can be put anywhere that expects a sequence. That'd be as cheap as None (modulo a once-per-interpreter cost for the additional static object).
Historically, annotations dicts are mutable. I don't know how often people mutate them, but I would assume it's uncommon. So technically this would be a breaking change. But it does seem low-risk.