
On Tue, Jan 12, 2021 at 11:31 AM Jim J. Jewett <jimjjewett@gmail.com> wrote:
Larry Hastings wrote:
The control-flow exclusion is for /module//attribute/ or /class attribute/ annotations: class C: if random.random() > 0.5: my_attr:int=3 else: my_attr2:float=3.5
That very example would be helpful in the FAQ, though I understand if you're concerned about making a minor sub-section seem too long.
This elucidates a crucial point to me: Larry's proposal looks at the source code of the annotations.
If I understand correctly, the problem is that you can't store multiple alternative annotations on my_attr. Therefore:
class C: my_attr:(int if random.random > 0.5 else float)
should be OK, because there is only a single annotation.
Does that mean that the generated function would contain the entire expression `(int if random.random > 0.5 else float)`? I guess that's what it has to mean. But the PEP only uses such simple examples that it's easy to miss this. -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>