wenkokke / talonfmt

Formatter for Talon files.
MIT License
6 stars 3 forks source link

AttributeError: 'tree_sitter.TreeCursor' object has no attribute 'current_field_name' #98

Closed pokey closed 1 year ago

pokey commented 1 year ago

We've started seeing errors like the following in pre-commit:

talonfmt.................................................................Failed
- hook id: talonfmt
- exit code: 1

Traceback (most recent call last):
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/bin/talonfmt", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/talonfmt/cli.py", line 176, in cli
    format_file(file_or_dir)
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/talonfmt/cli.py", line [165](https://github.com/cursorless-dev/cursorless/actions/runs/6109775312/job/16581465472#step:7:170), in format_file
    output = format(contents, encoding=encoding, filename=str(filename))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/talonfmt/cli.py", line 136, in format
    output = talonfmt(
             ^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/talonfmt/__init__.py", line 49, in talonfmt
    ast = parse(contents, encoding=encoding, raise_parse_error=True)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/tree_sitter_talon/internal/core.py", line 81, in parse
    return self.from_tree_sitter(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/tree_sitter_type_provider/__init__.py", line 141, in from_tree_sitter
    return self._from_tree_cursor(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/tree_sitter_type_provider/__init__.py", line 195, in _from_tree_cursor
    convert_child(tscursor)
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/tree_sitter_type_provider/__init__.py", line 169, in convert_child
    field_name = tscursor.current_field_name()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'tree_sitter.TreeCursor' object has no attribute 'current_field_name'
Traceback (most recent call last):
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/bin/talonfmt", line 8, in <module>
    sys.exit(cli())
             ^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/talonfmt/cli.py", line 176, in cli
    format_file(file_or_dir)
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/talonfmt/cli.py", line 165, in format_file
    output = format(contents, encoding=encoding, filename=str(filename))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/talonfmt/cli.py", line 136, in format
    output = talonfmt(
             ^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/talonfmt/__init__.py", line 49, in talonfmt
    ast = parse(contents, encoding=encoding, raise_parse_error=True)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/tree_sitter_talon/internal/core.py", line 81, in parse
    return self.from_tree_sitter(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/tree_sitter_type_provider/__init__.py", line 141, in from_tree_sitter
    return self._from_tree_cursor(
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/tree_sitter_type_provider/__init__.py", line 195, in _from_tree_cursor
    convert_child(tscursor)
  File "/home/runner/.cache/pre-commit/repotk7kjk5k/py_env-python3/lib/python3.11/site-packages/tree_sitter_type_provider/__init__.py", line [169](https://github.com/cursorless-dev/cursorless/actions/runs/6109775312/job/16581465472#step:7:174), in convert_child
    field_name = tscursor.current_field_name()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'tree_sitter.TreeCursor' object has no attribute 'current_field_name'

Error: Process completed with exit code 1.

See eg https://github.com/cursorless-dev/cursorless/actions/runs/6109775312/job/16581465472

Seems to happen on all PR branches, and I don't think we've changed anything. Seems like maybe some version bump somewhere. Maybe a Python 3.11 issue?

I haven't done any digging, but figured I'd drop an issue to see if you have idea what might be causing this one

wenkokke commented 1 year ago

Might be due to changes in the Python tree-sitter API?

wenkokke commented 1 year ago

Oof,tree-sitter turned current_field_name from a method in 0.20.1 into a property in 0.20.2… That’s a major change with a patch version increase.

pokey commented 1 year ago

ha wow that's pretty brutal 😅. Sounds like an easy fix tho?

wenkokke commented 1 year ago

yeah, but all previous versions of py-tree-sitter-talon would remain broken, so I'd have to find a fix... unfortunately, pypi doesn't let you update version bounds of existing packages :(

pokey commented 1 year ago

Can you use a try catch so that it works with both new and old version?

wenkokke commented 1 year ago

I could just check the package version. My concern is that past versions of py-tree-sitter-type-provider are irrevocably broken.

There's the possibility of yanking the broken release, but we'll have to see what the tree-sitter developers do.

pokey commented 1 year ago

Cross-linking https://github.com/tree-sitter/py-tree-sitter/issues/152

wenkokke commented 1 year ago

@pokey With the new release of tree-sitter-type-provider, does this still happen? (You’d have to find a way to update talonfmt’s dependencies, such as reinstalling.)

wenkokke commented 1 year ago

If this trouble persists, I may have to yank all versions of tstp before the latest one...

pokey commented 1 year ago

If you're following semantic versioning, then I believe all previous versions of tstp will be broken no matter what you do, because you're not allowed to alter previous versions

Is tstp the only library that directly refers to the method that became a property? If so, I would argue to modify the code to use the new property and declare its tree-sitter dependency version to >=0.20.2

wenkokke commented 1 year ago

I'm switching to exact versions for tree-sitter rather than ranges, because I don't want to set up tests that test explicitly against versions. I'm also yanking every previous version of tstp. If there's any issues that arise from that, due to unknown downstream dependants, I'll publish a post-release for the yanked version.

pokey commented 1 year ago

Yeah I think exact versions is reasonable for pre-1.0 deps. Annoying that it will cause challenging dependency resolution. I think the best you can do is try to pin to the latest version so if other libraries depend on you, they need to upgrade rather than downgrade to match your deps

wenkokke commented 1 year ago

This should be fixed now.