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

Your example doesn't define any module attributes or class attributes inside flow control statements, so that code should work fine.  (Defining functions/methods inside flow control statements isn't a problem.)


Cheers,


/arry

On 1/11/21 1:39 PM, Jim J. Jewett wrote:
Could you be more explicit about what is banned by the control-flow exclusion?

I'm assuming that:

    class A:
        bar=float
        if FOO:
            bar=int
            def a(x:int, y:int)->int   # function defined with annotations inside control flow
                return x+y

        def b(x:bar)  # function annotated with value that depends on control flow

is OK, and you're just talking about direct access to (the unfinished class or module).__annotations__ but I'm not certain.

-jJ
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/VMPMQWCGWR7LRFCEK57VJTQVV6TCQOQN/
Code of Conduct: http://python.org/psf/codeofconduct/