-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gazelle seems to not like PEP 695 β Type Parameter Syntax #2396
Comments
ah, dang: rules_python/gazelle/python/file_parser.go Lines 85 to 88 in 91e5751
I just tried this locally and got the same issue. @hunshcn do you have any additional insight for this? |
Opened smacker/go-tree-sitter#175. |
I think type parameter support was added to the tree-sitter grammer in tree-sitter/tree-sitter-python@71977ea, and should be included in grammer versions 0.20.4 and later. It looks like this was first included in go-tree-sitter in smacker/go-tree-sitter@8516e80. |
This is looking more and more like an issue with In our code base, I narrowed things down to a single line diff: # get_deps.py
# using this line is fine - tree-sitter correctly parses the module
def search_one_more_level(graph: dict[T, set[T]], seen: set[T], routes: list[list[T]], target: T) -> list[T] | None:
# using this line cause tree-sitter to fail parsing - see below
def search_one_more_level[T](graph: dict[T, set[T]], seen: set[T], routes: list[list[T]], target: T) -> list[T] | None: The only difference between the two lines is the addition of I added some debugging prints to --- a/gazelle/python/file_parser.go
+++ b/gazelle/python/file_parser.go
@@ -17,6 +17,7 @@ package python
import (
"context"
"fmt"
+ "log"
"os"
"path/filepath"
"strings"
@@ -184,6 +185,10 @@ func (p *FileParser) Parse(ctx context.Context) (*ParserOutput, error) {
if err != nil {
return nil, err
}
+ if strings.Contains(p.relFilepath, "get_deps.py") {
+ log.Printf("after parsing file, got rootNode=%q", rootNode)
+ }
p.output.HasMain = p.parseMain(ctx, rootNode) And ran gazelle.
So something is up with |
@maffoo yes I agree; the 3.12 grammar was added to tree-sitter a while ago. rules_python is currently pinning to the version just before I tried forking go-tree-sitter and hacking things to use the old |
As I understand it we are using the standard Lines 188 to 193 in 155efce
And then we use two targets which are created automatically by this import: rules_python/gazelle/python/BUILD.bazel Lines 45 to 46 in 155efce
Is it possible to define a more custom way to build that instead of relying on targets generated automatically by |
Actually, looks like the |
I checked out the
and then added a reference to this in the
This was enough to get |
Thanks Matthew! My next attempt was going to be to just move/copy those C flies into the |
While investigating #2396 and why #2413 doesn't appear to be working for us, I realized that one of the things I was making heavy use of was additional parser logging that I had added. This adds some of that logging. I also throw in some documentation because I found it helpful. Users can (attempt to) get additional parse failure information by setting the `GAZELLE_VERBOSE` environment variable to `1`. Eg: ```console $ GAZELLE_VERBOSE=1 bazel run //:gazelle ``` Here are some example logs: ```console $ GAZELLE_VERBOSE=1 bazel run //:gazelle INFO: Invocation ID: a4e026d8-17df-426c-b1cc-d3980690dd53 ... INFO: Running command line: bazel-bin/gazelle INFO: Streaming build results to: https://btx.cloud.google.com/invocations/a4e026d8-17df-426c-b1cc-d3980690dd53 gazelle: WARNING: failed to parse "hello/get_deps.py". The resulting BUILD target may be incorrect. gazelle: Parse error at {Row:1 Column:0}: def search_one_more_level[T](): gazelle: The above was parsed as: (ERROR (identifier) (call function: (list (identifier)) arguments: (argument_list))) gazelle: ERROR: failed to generate target "//hello:get_deps" of kind "py_library": a target of kind "pyle_py_binary" with the same name already exists. Use the '# gazelle:python_library_naming_convention' directive to change the naming convention. $ $ bazel run //:gazelle INFO: Invocation ID: 726c9fd6-f566-4c30-95ef-c4781ad155de ... INFO: Running command line: bazel-bin/gazelle INFO: Streaming build results to: https://btx.cloud.google.com/invocations/726c9fd6-f566-4c30-95ef-c4781ad155de gazelle: WARNING: failed to parse "hello/get_deps.py". The resulting BUILD target may be incorrect. gazelle: ERROR: failed to generate target "//hello:get_deps" of kind "py_library": a target of kind "pyle_py_binary" with the same name already exists. Use the '# gazelle:python_library_naming_convention' directive to change the naming convention. ``` --------- Co-authored-by: Richard Levasseur <[email protected]> Co-authored-by: Richard Levasseur <[email protected]>
TL;DR: I think we need to bump go-tree-sitter for python 3.12 support.
π bug report
Affected Rule
Gazelle
Is this a regression?
I could argue it either way, lol. I'm going to go with "probably" because it's related to #1895.
Description
PEP 695 added a Type Parameter syntax that looks like:
If a python file uses this new
def func[T](...)
syntax, and the file hasif __name__ == "__main__"
, then Gazelle will incorrectly generate apy_library
target rather thanpy_binary
.π¬ Minimal Reproduction
bazel run //:gazelle
Expected Result
Actual Result
π₯ Exception or Error
None
π Your Environment
Operating System:
gLinux
Output of
bazel version
:Rules_python version:
Anything else relevant?
I haven't been able to find a human-readable changelog of
tree-sitter
orgo-tree-sitter
that explicitly says when it added support for python 3.12...The text was updated successfully, but these errors were encountered: