开发者

TypeError: object.__new__() takes no parameters when using inheritance

Hey, I'm having a hard time implementing something, that I guess shouldn't be hard. I've been reading many posts, and I still can't figure it out, though it is probably answered, and I might just simply not understand the answer :/

So, I have a class, defining an algorithm file three_dpll.py in logics/ and a couple of helper functions

class three_dpll(object):
    ...
    def __extend__(self, symbol, value, mod):
            """ __extend__(symbol, value) - extends the model
            ...
            """

    def three_dpll(self, formula, symbols, mod):
            """ three_dpll(formula, symbols, mod) - calculates 3-DPLL \n
            NOTE: This algorithm should not be overwritten in any derived class!!"""
            ...
            # find unit clause
            curr_data = self.__find_unit_clause__(formula, mod)
            current_symbol = curr_data[0]
            current_symbol_set.add(current_symbol)
            current_value = curr_data[1]
            if current_symbol != None: 
                return three_dpll(formula, symbols - current_symbol_set,
                                  self.__extend__(current_symbol, current_value, mod))
            ...

and a logic that should implement the algorithm for a certain logic, where I might redefine certain methods like from logics.three_dpll.py (or any other helper function for that matter )

from three_dpll import three_dpll
class kleene_logic(three_dpll):
    """ This is the definition of Kleene logic """
    pass

and now calling it from a function in another file:

def satisfiable(logic, formula):
    """ satisfiable - \
    takes a logic and a set of formula and returns true or false"""
    # model is empty dictionary
    model = {}
    # symbols is a set
    symbols = set()
    my_logic = "logics."+logic # logic is passed as string to the script
    __import__(my_logic, fromlist=['three_dpll'])
    log = modules[my_logic]
    used_logic = log.kleene_logic()
    for clause in formula:
        ite = iter(clause)
        for literal in ite:
            symbols.add(abs(literal))
    try:
        return used_logic.three_dpll(formula, symbols, model)
    except FormulaValid.FormulaValid:
        return True

The error I get is:

in three_dpll
    self.__extend__(current_symbol, current_value, mod)) TypeError: object.__new_开发者_Go百科_() takes no parameters

Any ideas on how to fix this?


Your class three_dpll also has a method three_dpll. When you

return three_dpll(...)

you are creating an instance of that class (instead of calling the method, which is probably what you wanted to do). The class has no __init__() function that could handle the arguments that you are giving. That is what the error message tells you.

What you want is probably something like

return self.three_dpll(...)

which would call the method. Not shure if it solves your problem, but that should explain something.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜