Solution to forward references #179
Replies: 5 comments
-
Is there a scenario where this is needed? in any case, if you import annotations from |
Beta Was this translation helpful? Give feedback.
-
All in all, let's try to fix up what we can, at least to first get rid of the nasty import cycles so that we move on to the next task. We can continue typing any other time. |
Beta Was this translation helpful? Give feedback.
-
Yes, The Message Object |
Beta Was this translation helpful? Give feedback.
-
@kallyas I didn't get any errors doing something like this class Test:
def __init__ (self):
self.att:Test = None I'm sorry, I think I deleted the initial comment you had written by mistake, cause I can't seem to find it |
Beta Was this translation helpful? Give feedback.
-
Fo
For that, I fixed it later on |
Beta Was this translation helpful? Give feedback.
-
So I think we've faced the problem of forward referencing first-hand. I used to hear about it in the typing world but I'd never given it much thought till today. Fortunately there were solutions that were designed for it. we're going to use the
typing.TYPE_CHECKING
constant and also the__future__.annotations
feature. exampleif we put our controversial imports under TYPE_CHECKING, they will be blocked from the runtime environment but available to the type checker, which will work for us. so this is the way to go around the forward referencing.
@kallyas @edger-asiimwe @ushergodwin
Beta Was this translation helpful? Give feedback.
All reactions