-
Notifications
You must be signed in to change notification settings - Fork 541
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 |
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: