Fwd: A typing question
Paulo da Silva
p_d_a_s_i_l_v_a_ns at nonetnoaddress.pt
Sun Oct 30 15:13:56 EDT 2022
Às 22:34 de 29/10/22, dn escreveu:
> Out of interest, tested snippet in PyCharm, cf native-mypy. It flags the
> original:
>
> GLOBALS.foos: Optional[Foos]=Foos()
>
> but not the fall-back:
>
> GLOBALS.foos=Foos()
>
>
> Must admit, the first query coming to mind was: why is the typing taking
> place at initialisation-time, rather than within the (class) definition?
> At definition time "foos" has already been typed as None by implication!
>
>
> Solution (below) will not work if the mention of Foos in GLOBALS is a
> forward-reference. Either move GLOBALS to suit, or surround "Foos" with
> quotes.
Somehow I missed this sentence the 1st. time I read this post :-(
This is good enough to me! Thank you.
I didn't know about this "quoting" thing.
Regards
Paulo
More information about the Python-list
mailing list