Linked List Type Error
<p>I am a beginner and I started learning python programming and I am stuck with an error. I get a type error</p>

<pre><code>class Node:

    def __init__(self):
        self.data = None
        self.next = Node

    def setData(self,data)
        self.data = data

    def getData(self):
        return self.data

    def setNext(self,next):
        self.next = next

    def getNext(self):
        return self.next

    def hasNext(self):
        return self.next!=None


class LinkedList(object):

    def __init__(self):
        self.length = 0
        self.head = None

    def listLength(self):
        currentNode = self.head
        length = 0

        while currentNode.hasNext:
            length = length + 1
            currentNode = currentNode.getNext()
        return length

"""
Methods to Insert nodes in a Linked List:
# insertNode: Use this method to simply insert a node to the Linked List
# insertHead: Use this method to insert a node at the head of the Linked List
# insertTail: Use this method to insert a node at the tail of the Linked List
# insertAtPosition: Use this method to insert a node at a particular position of the Linked List
"""

    def insertNode(self,node):
        if self.length == 0:
            self.insertHead(node)
        else:
            self.insertTail(node)

    def insertHead(self, data):
        nodeToBeInserted = Node()
        nodeToBeInserted.setData(data)
        if self.length == 0:
            self.head = nodeToBeInserted
        else:
            nodeToBeInserted.setNext(self.head)
            self.head = nodeToBeInserted
        self.length = self.length + 1

    def insertTail(self,data):
        nodeToBeInserted = Node()
        nodeToBeInserted.setData(data)
        currentNode = self.head

        while currentNode.getNext() != None:
            currentNode = currentNode.getNext()
        currentNode.setNext(nodeToBeInserted)
        self.length = self.length + 1

    def insertAtPosition(self,data, position):
        if position &gt; self.length or position &lt; 0:
            print("Invalid position!, The size of the Linked List is:%s"%self.length)
        else:
            if position ==0:
                self.insertHead(data)
            else:
                nodeToBeInserted = Node()
                nodeToBeInserted.setData(data)
                currentNode = self.head
                count = 0
                while count &lt; position - 1:
                    currentNode = currentNode.getNext()
                    count = count + 1
                nodeToBeInserted.setNext(currentNode.getNext())
                currentNode.setNext(nodeToBeInserted)
                self.length = self.length+1

ll = LinkedList()
ll.insertNode(1)
ll.insertNode(2)
ll.insertNode(3)
</code></pre>

<p>The error I am seeing is:</p>

<pre><code>Traceback (most recent call last):
  File "C:/Users/XPS 13/PycharmProjects/DataStructures/LinkedList/Implementation/SinglyLinkedList.py", line 154, in &lt;module&gt;
ll.insertNode(2)
  File "C:/Users/XPS 13/PycharmProjects/DataStructures/LinkedList/Implementation/SinglyLinkedList.py", line 92, in insertNode
self.insertTail(node)
  File "C:/Users/XPS 13/PycharmProjects/DataStructures/LinkedList/Implementation/SinglyLinkedList.py", line 121, in insertTail
while currentNode.getNext() != None:
TypeError: getNext() missing 1 required positional argument: 'self'

Process finished with exit code 1
</code></pre>

<p>If someone can please explain me the reason for this error it will be appreciated.</p>

<p>Thank you.</p>

<p><code>while currentNode.hasNext</code> is always true, because it is a method.</p>

<p>On the other hand, <code>while currentNode.hasNext()</code> might be false at some point.</p>

<hr>

<p><code>self.next = Node</code> means the class is next.</p>

<p>On the other hand, <code>self.next = Node()</code> would make a new instance.</p>

<p>But I guess you don't want that, because it would try to create an endless linked list, so <code>self.next = None</code> might be better.</p>

<p>This causes <code>currentNode = currentNode.getNext()</code> to assign the class to <code>currentNode</code> and then later, the next call to <code>currentNode.getNext()</code> is actually calling <code>Node.getNext()</code> which causes this error.</p>

python linked-list typeerror