tree-sitter / py-tree-sitter

Python bindings to the Tree-sitter parsing library
https://tree-sitter.github.io/py-tree-sitter/
MIT License
817 stars 96 forks source link

TypeError on initializing Language with tree_sitter_python after following example code in readme. #239

Closed bohemian-miser closed 4 months ago

bohemian-miser commented 4 months ago

Description

I encountered a TypeError when trying to initialize a Language object using the tree_sitter_python module following the example code in the README. I am trying to set up Tree-sitter for Python code parsing.

Steps to Reproduce

  1. Environment:
    • Python version: 3.8.10
    • Tree-sitter version: [version]
    • OS: Linux, Debian-based

I used a fresh install of both tree-sitter and tree-sitter-python

$ pip install tree-sitter-python
Collecting tree-sitter-python
  Downloading tree_sitter_python-0.21.0-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (1.8 kB)
Downloading tree_sitter_python-0.21.0-cp38-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (130 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 130.6/130.6 kB 12.4 MB/s eta 0:00:00
Installing collected packages: tree-sitter-python
Successfully installed tree-sitter-python-0.21.0

$ pip install tree-sitter
Collecting tree-sitter
  Using cached tree_sitter-0.21.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (10 kB)
Using cached tree_sitter-0.21.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (503 kB)
Installing collected packages: tree-sitter
Successfully installed tree-sitter-0.21.3
  1. Code:

    import tree_sitter_python as tspython
    from tree_sitter import Language, Parser
    
    PY_LANGUAGE = Language(tspython.language())
  2. Expected: I expected the Language object to be initialized without errors.

  3. Actual: TypeError: init() missing 1 required positional argument: 'name'

ObserverOfTime commented 4 months ago
pip install -U tree-sitter
njuweicheng commented 3 months ago

This is actually caused by the Python version. The latest tree-sitter requires Python >= 3.9.