Need help understanding "TypeError: by default, __new__ does not accept any parameters" error in python

For some reason, I am having problems with my head around __init__ and __new__ . I have a bunch of code that works fine with the terminal, but when I load it as a plugin for the Google Quick Search Box, I get a TypeError: default __new__ takes no parameters error message.

I read about the error, and it somehow made my brain spin. At its core, I have 3 classes, without subclasses, each class has its own def s. I never use def __init__ or def __new__ , but I realized that these are functions (or their absence) that will give me an error.

I have no idea how to sum the code up to the snippet, which will be useful here, since I'm a little over the head, but the whole script can be found on github . Not expecting anyone to correct my code for me, I'm just on that mind. Simple (plain English, not a quote from python docs that I read 20 times and still don't quite understand), an explanation of why this error __new__ or why I should or should not, using __init__ and / or __new__ would be seriously appreciated.

+4
source share
2 answers

The easiest way to reproduce your problem:

 >>> class Bah(object): pass ... >>> x = Bah(23) Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: default __new__ takes no parameters 

So it looks like there is a class in your code (and not when starting from the terminal, but then you are doing a completely different import) that does not have __init__ , and you call the class somewhere with some parameters. In error tracing, you should get the place where the call occurs (if not, for example, due to the subtleties of the GUI, you can use try / except in everything and make sure that you drop the trace to the / tmp file in the except clause, use the traceback module from standard library).

+8
source

There are several concepts for building a base class that you think are missing.

The __init__ method is used when the class is first init ialized, and how you configure its internal elements. You also want to use the new-style Python classes (the default in Python 3).

I suggest starting with Dive Into Python and splitting out from there.

+2
source

Source: https://habr.com/ru/post/1303875/


All Articles