Skip to content

Improve evaluation of class, decorated class, and decorated function definitions in Python with examples#618

Merged
Olical merged 6 commits intoOlical:mainfrom
russtoku:main
Nov 17, 2024
Merged

Improve evaluation of class, decorated class, and decorated function definitions in Python with examples#618
Olical merged 6 commits intoOlical:mainfrom
russtoku:main

Conversation

@russtoku
Copy link
Contributor

Improved evaluation with <localleader>ee for class definitions and decorated class and function definitions in the Python client. Added some representative code for these cases to sandbox.py.

(= "for_statement" (node:type))
(= "call" (node:type))))
(log.dbg "form-node?: node:type =" (node:type))
(log.dbg "form-node?: node:parent =" (node:parent))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh good idea for a debug line, this will help diagnose some things.

(not (= "decorated_definition" (parent:type)))) true
(and (= "function_definition" (node:type))
(not (= "decorated_definition" (parent:type)))) true
false)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I assume this is inspired by the Julia client changes? Discovering that :InspectTree thing has made this a lot easier to reason about thankfully.

Not sure if we explicitly need to return true or false here though, I feel like we can get away with truthy and falsy. But if this is easier to reason about or you had issues without explicit boolean return values then this is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I took inspiration from your changes to the Julia client while working on trying to upgrade an ancient Django project from version 1.9.

I was having some trouble getting the evaluation of classes and decorated classes/functions. In anger, I just did the simplest thing to keep me from confusing myself.

@Olical Olical merged commit c39e9b7 into Olical:main Nov 17, 2024
@Olical
Copy link
Owner

Olical commented Nov 17, 2024

Tried it out locally and it works wonderfully, thanks! This tree sitter system is working pretty well 😄

@russtoku
Copy link
Contributor Author

Thanks for making Conjure and making all of this possible!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants