Birhan Abuhay
Birhan Abuhay

Reputation: 11

TypeError: `__init__()` takes exactly 1 argument (2 given)

1. I'm encountering an error while trying to create a parser for 'c'. The error message is as follows:

Error creating parser for 'c': __init__() takes exactly 1 argument (2 given). Traceback: Traceback (most recent call last):
  File "F:\Thes_Dev\SourceParser\scripts\parse_functions.py", line 129, in get_parser
    language = Language(lib_path, language_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: __init__() takes exactly 1 argument (2 given)

Details:

Context:

I'm trying to initialize a Language object with lib_path and language_name as arguments. However, it seems like the __init__ method of the Language class is only expecting one argument.

Question:

How can I resolve this error? Is there a mistake in how I'm passing the arguments to the Language class, or do I need to modify the __init__ method of the Language class to accept two arguments?

Any help would be greatly appreciated!

Upvotes: 0

Views: 239

Answers (1)

AKX
AKX

Reputation: 169051

The readme for tree-sitter-py says to do

import tree_sitter_python as tspython
from tree_sitter import Language, Parser
PY_LANGUAGE = Language(tspython.language())
parser = Parser(PY_LANGUAGE)

so that does indicate tree_sitter.Language() accepts only one parameter, and you're now passing it two, hence the error.

Upvotes: 0

Related Questions