Click here to Skip to main content
15,868,099 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What is the syntax for node: Node? Because when I execute it, it complains that the name 'Node' is not specified.
Python
class Node:
    def append_child(self, node: Node):
       if node != None:
        self.first_child = node
    self.child_nodes += [node]

I'm not sure how to accomplish type casting in Python, however, I did some research and found this information. But I'm still perplexed.

What I have tried:

Should I just delete the: Node and do an instant check within the function? But how could I then access the attributes of the node (which I would assume to be instances of the Node class)?
Posted
Updated 15-Nov-22 3:04am
v2

1 solution

you should use
Python
from __future__ import annotations
see: Stack Overflow - How do I type hint a method with the type of the enclosing class?[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900