Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

How to use an inner class as a type annotation in another inner class?

$
0
0

I have the next structure of classes:

class Root:    @dataclass    class Leaf:        pass    @dataclass    class Node:        leaf: Leaf

The problem is PyCharm doesn't see Leaf class, I also tried to specify it as leaf: Root.Leaf and even 'Root'.Leaf... There was same result.
How to declare a field type in the inner class if the type is another inner class? Is it possible in python?
P.S. I can make the Leaf class an inner of the Node class but I am interested in my example.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>