Python Forum
Why am I getting this TypeError? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Why am I getting this TypeError? (/thread-40924.html)



Why am I getting this TypeError? - pitosalas - Oct-14-2023

Maybe it's early morning brain...The line called out is:
self.new_queue = Queue("New", sim)
and the error says:
Error:
TypeError: Queue.__init__() takes from 1 to 2 positional arguments but 3 were given
and the declaration says:
class Queue:
    def __init__(self, name: str, sim):



RE: Why am I getting this TypeError? - menator01 - Oct-14-2023

Please post the code and errors using the bbtags. Can't tell much from images.


RE: Why am I getting this TypeError? - pitosalas - Oct-14-2023

(Oct-14-2023, 12:28 PM)menator01 Wrote: Please post the code and errors using the bbtags. Can't tell much from images.

Can’t find how to do it. Tried but doesn’t seem to do the trick…


RE: Why am I getting this TypeError? - menator01 - Oct-14-2023

A video of how to



RE: Why am I getting this TypeError? - deanhystad - Oct-14-2023

This example runs with no error.
class Queue:
    def __init__(self, name: str, sim):
        pass

new_queue = Queue("New", True)
The error message says that Queue is defined like this:
class Queue:
    def __init__(self, name=""):
I think Queue is not what you think it us. Is Queue a class you wrote, or is it imported?


RE: Why am I getting this TypeError? - DeaD_EyE - Oct-15-2023

If you imported Queue from module queue, then you can use only one argument, which is the maxsize of the queue. The modules asyncio and multiprocessing modules have also a Queue implementation, which takes also maxsize.

If Queue is your implementation in a different module, then pay attention if you overload with an import your class.

from utils import Queue
from queue import Queue

# Queue is now form queue

# different order
from queue import Queue
from utils import Queue

# Queue is now form utils
Another possible error:
class Queue:
    def __init__(self, name, simu): ...

# later in code
class Queue:
    def __init__(self, name): ...

# calling now Queue, calls the latest definition of Queue,
# which takes only one argument. (the self is given implicit and is the instance of the class)