Strange mismatch of Python arguments

Viewed 70

While testing some code, I was given an error:

TypeError: breadth_first_search() takes from 2 to 3 positional arguments but 4 were given

The parameter bit of the function declaration looks like this:

def breadth_first_search(self, id: int, level=None)

The call looks like this:

tree.breadth_first_search(parent_id)

As far as I'm aware, this should be correct. I don't know why it would interpret my one argument (or two, including self) as four. Is there something plain that I'm missing?

--

For completeness, here's the traceback:

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    tree = FeatureQuery.load_feature_tree("general", inventory)
  File "D:\Speechcraft\Python\core\ling_query.py", line 201, in load_feature_tree
    FeatureQuery.load_feature_node_recursive(feature_inventory, tree, results, l)
  File "D:\Speechcraft\Python\core\ling_query.py", line 221, in load_feature_node_recursive
    parent = tree.breadth_first_search(parent_id)
  File "D:\Speechcraft\Python\core\phonological_units.py", line 37, in breadth_first_search
    return self.breadth_first_search(self, id, next_level)
TypeError: breadth_first_search() takes from 2 to 3 positional arguments but 4 were given
1 Answers

It turned out to be a silly mistake. I accidentally included self as a parameter in the recursive call. Thanks go to user2357112 supports monica.

Related