Skip to content

Conversation

@toaction
Copy link
Contributor

@toaction toaction commented Oct 13, 2025

fix #45

@gemini-code-assist
Copy link

Summary of Changes

Hello @toaction, 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 significantly enhances the pydump tool by adding comprehensive support for analyzing Python-defined classes. It enables the extraction of class details such as inheritance hierarchies, various types of methods (instance, class, static), and properties, providing a richer and more structured representation of Python modules.

Highlights

  • Python Class Parsing: Introduced new functionality to pydump for parsing and extracting detailed information about Python classes, including their inheritance, methods (instance, class, static), and properties.
  • New class.go file: Added _xtool/pydump/class.go to encapsulate the logic for parsing Python class structures.
  • Signature Extraction Enhancement: Updated the getSignature function in pydump.go to handle method signatures more accurately by allowing the skipping of the first parameter (e.g., self) and returning errors for non-callable objects.
  • Symbolic Representation for Classes: Extended the symbol package with new Go structs (Class, Base, Property) to represent Python class metadata, integrating them into the Module structure.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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

  1. 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.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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 adds support for dumping Python class definitions, which is a great feature. The changes are mostly in a new class.go file and modifications to existing data structures and parsing logic. I've found a few areas with potential for panics due to unsafe C-API interactions, a bug in signature parsing, and some opportunities for improvement in consistency and feature completeness. Overall, good work on expanding the tool's capabilities.

@xgopilot
Copy link

xgopilot bot commented Oct 13, 2025

Code Review Summary

Great work on adding Python class dumping support! The implementation is well-structured and comprehensive. However, there are critical security issues that need addressing before merge.

🔴 Critical Issues (Must Fix)

Nil Pointer Dereferences: Multiple locations lack defensive nil checks when calling Python C API methods. These could crash the application with malicious input:

  • class.go:50, 57-58 - parseBases() missing nil checks
  • class.go:72-74 - parseClassDict() tuple operations unchecked
  • class.go:189 - getRealDictItems() missing checks on CallOneArg/DictItems
  • pydump.go:49 - getSignature() missing Str() nil check

Fix: Add nil checks after each GetAttrString/Type/TypeName/CStr call.

⚡ Performance Issue

Repeated module imports (class.go:15): getBuiltinDictFunc() imports builtins module on every class. Cache using sync.Once for 20-50% speedup on multi-class modules.

📝 Code Quality

  • Reduce duplication: Combine classmethod/staticmethod cases (class.go:100-120)
  • Fix JSON inconsistency: Bases field has singular tag "base" (symbol.go:33)
  • Improve removeFirstParam to handle return type annotations (pydump.go:68)
  • Add function documentation for parseClass, parseClassDict, parseProperty

✅ Strengths

  • Clear separation of concerns
  • Comprehensive method type handling (init, instance, class, static, properties)
  • Good error propagation pattern

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pydump support Python defined class

1 participant