A named parameter can be used in placed of an anonymous parameter, so the Protocol works as a value for the Callable. The first assignment copy_a = copy_b
silently promotes copy_a
to a Copy
, which is then valid to assign to copy_b: Copy
.
...
copy_a = copy_b # copy_a is a Copy now!
copy_b = copy_a # assign copy_a: Copy to copy_b: Copy
reveal_type(copy_a) # Revealed type is 'aaa_testbed.Copy'
Swapping the assignment means copy_b = copy_a
happens while copy_a
is still the anonymous type. This triggers the expected error:
...
copy_b = copy_a # Incompatible types in assignment (expression has type "Callable[[T], T]", variable has type "Copy")
copy_a = copy_b
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…