codebleu icon indicating copy to clipboard operation
codebleu copied to clipboard

TypeError: an integer is required

Open PiXianDouBanJiang opened this issue 1 year ago • 15 comments

I failed on the given example with a typeerror.

TypeError Traceback (most recent call last) Cell In[1], line 6 3 prediction = "def add ( a , b ) :\n return a + b" 4 reference = "def sum ( first , second ) :\n return second + first" ----> 6 result = calc_codebleu([reference], [prediction], lang="python", weights=(0.25, 0.25, 0.25, 0.25), tokenizer=None) 7 print(result)

File d:\cc\LLM_DynaEval_Coding\mbpp+\codebleu\codebleu.py:41, in calc_codebleu(references, predictions, lang, weights, tokenizer, keywords_dir) 38 assert keywords_dir.exists(), f"keywords_dir {keywords_dir} does not exist" 40 # get the tree-sitter language for a given language ---> 41 tree_sitter_language = get_tree_sitter_language(lang) 43 # preprocess inputs 44 references = [[x.strip() for x in ref] if isinstance(ref, list) else [ref.strip()] for ref in references]

File d:\cc\LLM_DynaEval_Coding\mbpp+\codebleu\utils.py:163, in get_tree_sitter_language(lang) 160 elif lang == "python": 161 import tree_sitter_python --> 163 return Language(tree_sitter_python.language()) 164 elif lang == "go": 165 import tree_sitter_go

TypeError: an integer is required

PiXianDouBanJiang avatar Sep 08 '24 09:09 PiXianDouBanJiang

pip install tree-sitter-python==0.21

will solve the problem.

chao-peng avatar Sep 09 '24 12:09 chao-peng

pip install tree-sitter-python==0.21 did not work for me. @PiXianDouBanJiang did you find a way to make it work?

ranimkhojah avatar Oct 02 '24 17:10 ranimkhojah

I got it working with tree-sitter==0.23.1 and codebleu==0.7.1. The latter is not built and uploaded to PyPI yet, so you'd have to pip install git+https://github.com/k4black/codebleu#egg=codebleu.

aur3l14no avatar Oct 10 '24 11:10 aur3l14no

I’m also encountering the TypeError: an integer is required issue with tree-sitter==0.23.1 and codebleu==0.7.1. I tried pip install tree-sitter-python==0.21 as suggested by @chao-peng and installing CodeBLEU directly from GitHub as suggested by @aur3l14no, but neither resolved the issue. Has anyone found a reliable solution?

raptech-jp avatar Nov 02 '24 15:11 raptech-jp

I have an update. I wasn’t able to resolve the issue on my x86 Ubuntu environment, but I managed to get it working on an M3 MacBook with the following setup:

% pip freeze
codebleu==0.7.0
tree-sitter==0.23.2
tree-sitter-python==0.23.2

raptech-jp avatar Nov 03 '24 06:11 raptech-jp

pip install tree-sitter-python==0.21

will solve the problem.

Thanks,this method has solved my question.

Weigang-Wu avatar Nov 18 '24 02:11 Weigang-Wu

Since this is resolved by installing tree-sitter-0.23.1, the commit in https://github.com/k4black/codebleu/commit/bedf9e8aff668a8559551e7ba590937dfd4647f2 should resolve the issue. It is just not yet released.

nielstron avatar Nov 19 '24 14:11 nielstron

Confirmed from @nielstron.

Since this is resolved by installing tree-sitter-0.23.1, the commit in bedf9e8 should resolve the issue. It is just not yet released.

The problem is caused by capabilities of tree-sitter.

Somehow the metadata of codebleu write the following incompatible dependency in ver. 0.7.0:

Requires-Dist: tree-sitter <0.23.0,>=0.22.0
Requires-Dist: setuptools >=61.0.0
Provides-Extra: all
Requires-Dist: tree-sitter-python~=0.21 ; extra == 'all'
Requires-Dist: tree-sitter-go ~=0.21 ; extra == 'all'
Requires-Dist: tree-sitter-javascript ~=0.21 ; extra == 'all'
Requires-Dist: tree-sitter-ruby ~=0.21 ; extra == 'all'
Requires-Dist: tree-sitter-php ~=0.22 ; extra == 'all'
Requires-Dist: tree-sitter-java ~=0.21 ; extra == 'all'
Requires-Dist: tree-sitter-c-sharp ~=0.21 ; extra == 'all'
Requires-Dist: tree-sitter-c ~=0.21 ; extra == 'all'
Requires-Dist: tree-sitter-cpp ~=0.22 ; extra == 'all'
Requires-Dist: tree-sitter-rust ~=0.21 ; extra == 'all'

this "tree-sitter-language~=0.21" means that the pip will automatically install any version of tree-sitter below 1.0. Right now the tree-sitter-language main version is 0.23.* that will be installed automatically by the line. This version is not compatible with tree-sitter==0.22.* https://github.com/tree-sitter/tree-sitter-python/issues/280 which will also be installed automatically by line Requires-Dist: tree-sitter <0.23.0,>=0.22.0 and then will cause exception as followed:

return Language(tree_sitter_python.language())
TypeError: an integer is required

The correct writting is ~=0.21.0, which means install any version below 0.22.0, which you can't dirrectly fixed in pypi or pip. At this moment, you will have both tree-sitter-language==0.23.* and tree-sitter==0.22.* in your environment.

So the manual fixing is to:

Update your tree-sitter to 0.23.* (this will cause your IDE capabilities warning as the metadata requires tree-sitter <0.23.0,>=0.22.0, but it works).

OR

Uninstall codebleu by pip-autoremove and reinstall ver. 0.7.1 through git+https://github.com/k4black/codebleu.git

OR

Downgrade ALL tree-sitter-language packages to ver. 0.22.0

Anyway, this bug will finally be fixed as the team release 0.7.1 on PyPi. I wish they can notice the problems of metadata and fix them before the next major update of tree-sitter.

RyanLoil avatar Jan 07 '25 09:01 RyanLoil

Installing codebleu 0.7.1 using pip install git+https://github.com/k4black/codebleu.git didn't work for me. I still get the same error:

return Language(tree_sitter_c.language())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: an integer is required
❯ pip list | egrep 'codebleu|tree-sitter*'
codebleu                          0.7.1
tree-sitter                       0.22.3

prvnsmpth avatar Mar 24 '25 04:03 prvnsmpth

Upgrading tree-sitter to version 0.24.0 on Ubuntu fixed the issue on my end.

MootezSaaD avatar Apr 01 '25 13:04 MootezSaaD

upgrading to tree-sitter-0.24.0 works for me

Minghao-Han avatar Apr 11 '25 13:04 Minghao-Han

pip install tree-sitter-python==0.21 will solve the problem.

thanks a lot, i need to parse c language. So i run "pip install tree-sitter-c==0.21" and the error disappears !

jack2223333 avatar May 08 '25 05:05 jack2223333

Confirmed from @nielstron.

Since this is resolved by installing tree-sitter-0.23.1, the commit in bedf9e8 should resolve the issue. It is just not yet released.

The problem is caused by capabilities of tree-sitter.

Somehow the metadata of codebleu write the following incompatible dependency in ver. 0.7.0:

Requires-Dist: tree-sitter <0.23.0,>=0.22.0
Requires-Dist: setuptools >=61.0.0
Provides-Extra: all
Requires-Dist: tree-sitter-python~=0.21 ; extra == 'all'
Requires-Dist: tree-sitter-go ~=0.21 ; extra == 'all'
Requires-Dist: tree-sitter-javascript ~=0.21 ; extra == 'all'
Requires-Dist: tree-sitter-ruby ~=0.21 ; extra == 'all'
Requires-Dist: tree-sitter-php ~=0.22 ; extra == 'all'
Requires-Dist: tree-sitter-java ~=0.21 ; extra == 'all'
Requires-Dist: tree-sitter-c-sharp ~=0.21 ; extra == 'all'
Requires-Dist: tree-sitter-c ~=0.21 ; extra == 'all'
Requires-Dist: tree-sitter-cpp ~=0.22 ; extra == 'all'
Requires-Dist: tree-sitter-rust ~=0.21 ; extra == 'all'

this "tree-sitter-language~=0.21" means that the pip will automatically install any version of tree-sitter below 1.0. Right now the tree-sitter-language main version is 0.23.* that will be installed automatically by the line. This version is not compatible with tree-sitter==0.22.* tree-sitter/tree-sitter-python#280 which will also be installed automatically by line Requires-Dist: tree-sitter <0.23.0,>=0.22.0 and then will cause exception as followed:

return Language(tree_sitter_python.language()) TypeError: an integer is required The correct writting is ~=0.21.0, which means install any version below 0.22.0, which you can't dirrectly fixed in pypi or pip. At this moment, you will have both tree-sitter-language==0.23.* and tree-sitter==0.22.* in your environment.

So the manual fixing is to:

Update your tree-sitter to 0.23. (this will cause your IDE capabilities warning as the metadata requires tree-sitter <0.23.0,>=0.22.0, but it works).*

OR

Uninstall codebleu by pip-autoremove and reinstall ver. 0.7.1 through git+https://github.com/k4black/codebleu.git

OR

Downgrade ALL tree-sitter-language packages to ver. 0.22.0

Anyway, this bug will finally be fixed as the team release 0.7.1 on PyPi. I wish they can notice the problems of metadata and fix them before the next major update of tree-sitter.

I solved my porblem by the first method. Thanks a lot!

smallQQ0227 avatar Jul 02 '25 07:07 smallQQ0227

Thanks! upgrading to tree-sitter-0.24.0 fixed the problem

RalLiu avatar Aug 26 '25 17:08 RalLiu

tree-sitter-0.24.0 works for me but may I know if we will have new releases for this repo?

nolanlwin avatar Nov 18 '25 22:11 nolanlwin