-
Notifications
You must be signed in to change notification settings - Fork 45
python: support recv method #1289
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
base: main
Are you sure you want to change the base?
Conversation
Code Review for PR #1289Todo List:
SummaryThis PR makes two related changes to Python function symbol handling:
Detailed Review✅ Positive AspectsConsistent Symbol Format: The changes ensure consistent use of Proper Method Handling: Adding receiver context to method signatures in 🔍 Code Quality & Best Practicescl/instr.go:439 // BEFORE
fnName := pysymPrefix + mod + "." + name
// AFTER
fnName := pysymPrefix + mod + "$" + name ✅ Good: This change maintains consistency with the ssa/python.go:597 // NEW CODE
if recv := sig.Recv(); recv != nil {
sig = FuncAddCtx(recv, sig)
} ✅ Good: Proper nil check before calling ssa/python.go:643 // BEFORE
if pos := strings.LastIndexByte(name, '.'); pos > 0 {
// AFTER
if pos := strings.LastIndexByte(name, '$'); pos > 0 { ✅ Good: Critical fix that makes 🚨 Potential Issues1. Breaking Change Risk
2. Symbol Collision Risk 3. Missing Edge Case Handling 💡 Suggestions for Improvement1. Add Input Validation // In modOf function, consider adding validation:
func modOf(name string) string {
if pos := strings.LastIndexByte(name, '$'); pos > 0 {
return name[:pos]
}
// Better error message with the actual name
panic(fmt.Sprintf("invalid python symbol name format: %q, expected format: 'module$function'", name))
} 2. Consider Symbol Escaping 📚 Documentation Consistency✅ No documentation updates needed: This appears to be an internal symbol format change that doesn't affect the public API. The change is consistent with existing internal patterns. 🏗️ Architecture & Design✅ Sound architectural decision: The changes improve consistency in symbol handling and ensure proper method signature processing. The modifications align well with the existing LLGO Python integration design. The receiver context addition ensures that:
🧪 Testing RecommendationsConsider adding tests for:
Overall Assessment✅ This is a well-implemented change that improves symbol consistency and adds necessary method receiver handling. The code quality is good and follows existing patterns in the codebase. Key strengths:
Areas for consideration:
The changes appear to be part of ongoing improvements to LLGO's Python integration and are architecturally sound. 👉 Want me to re-run this review? Just type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @visualfc, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces initial support for Python function receivers and refactors the internal symbol naming convention for Python functions. These changes aim to enhance the interoperability between Go and Python by allowing more complex Python constructs to be represented and processed correctly.
Highlights
- Python Function Naming: Modified the internal naming convention for Python functions by replacing the "." separator with "$" in generated symbols, improving symbol management.
- Receiver Support for Python Functions: Introduced logic to correctly handle function signatures that include a receiver within PyNewFunc, enabling proper integration of receiver-bound Python methods.
- Module Name Parsing Update: Updated the modOf utility function to align with the new "$" symbol separator for parsing module names, ensuring consistency across the codebase.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces support for handling the recv
operation in the Python backend of the compiler. It modifies the instr.go
file to change the function name prefix and updates python.go
to handle the recv
signature and module symbol loading. The changes aim to improve the compiler's ability to interact with Python code, particularly in scenarios involving asynchronous communication.
e5e09e0
to
7e5dee8
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1289 +/- ##
==========================================
- Coverage 90.18% 90.13% -0.06%
==========================================
Files 43 43
Lines 12674 12679 +5
==========================================
- Hits 11430 11428 -2
- Misses 1087 1094 +7
Partials 157 157 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
7e5dee8
to
ce9fecb
Compare
1a053a0
to
ae87ced
Compare
ae87ced
to
aa4a9d7
Compare
无法获取类属性类声明: class Dog(Animal):
DOGNAME = "Dog"
def __init__(self, name, age):
self._name = name
self._age = age
@property
def age(self):
return self._age LLGo Bindings: type Dog struct {
py.Object
}
//go:linkname NewDog py.Dog
func NewDog(name *py.Object, age *py.Object) *Dog
//llgo:link (*Dog).Age py.Dog.age.__get__
func (p *Dog) Age() *py.Object { return nil}
//llgo:link (*Dog).DogName py.Dog.DOGNAME.__get__
func (p *Dog) DogName() *py.Object { return nil} 调用 d := dog1.NewDog(py.Str("Dog"), py.Long(3))
fmt.Println(c.GoString(d.Age().Str().CStr()))
fmt.Println(c.GoString(d.DogName().Str().CStr())) 结果
|
//go:linkname DogName py.Dog.DOGNAME //go:linkname DogClass py.Dog |
69f7be7
to
8a0ff4d
Compare
389510d
to
e27e090
Compare
Uh oh!
There was an error while loading. Please reload this page.