Add Python stub module generation for IDE autocomplete#8
Open
chrishyoroklee wants to merge 4 commits intoBarnard-PL-Labs:mainfrom
Open
Add Python stub module generation for IDE autocomplete#8chrishyoroklee wants to merge 4 commits intoBarnard-PL-Labs:mainfrom
chrishyoroklee wants to merge 4 commits intoBarnard-PL-Labs:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
MaxPyLang lets users build Max patches in Python, but there's no way for IDE autocomplete or LLM agents
(like Claude, Cursor, Copilot) to know what Max objects exist. Users have to memorize object names and
manually write
MaxObject("cycle~")every time. The generated stub modules solve both problems: IDEscan autocomplete object names, and LLM agents can read the docstrings to understand what each object
does, what arguments it takes, and how to use it.
Example
Before:
After:
An LLM agent can read the docstring for
cycle_tildeand learn it's a sinusoidal oscillator, whatinlets/outlets it has, what attributes are available, and what related objects exist — all without
needing access to Max documentation.
Summary
reference files and stores it in JSON alongside existing object info
objects/max.py,objects/msp.py,objects/jit.py) containingpre-instantiated
MaxObjectvariables with rich docstrings, so users get IDE autocomplete and canwrite
patch.place(cycle_tilde)instead ofpatch.place(MaxObject("cycle~"))sanitize_py_name()to convert Max names to valid Python identifiers (cycle~→cycle_tilde,jit.gl.render→jit_gl_render,2d.wave~→_2d_wave_tilde,if→if_,dict→dict_)How it works
import_objs("vanilla")(one-time setup, Max must be open)generate_stubs()reads the JSON and writesmaxpylang/objects/{package}.pywith onevariable per object
from maxpylang.objects import cycle_tilde, metro, dac_tildeMaxObjectinstance —cycle_tilde.namereturns"cycle~"Generated stub format
Files changed
maxpylang/importobjs.py— Addedsanitize_py_name(),_build_docstring(),generate_stubs();wired into
import_objs(); addedimport keyword, builtinsmaxpylang/objects/__init__.py— New file. Re-exports from generated sub-modules with try/exceptguards
maxpylang/__init__.py— Added optionalfrom . import objectsEdge cases handled
~→_tilde,.→_,-→___MaxObjectarg validation warningsobjects/__init__.pydynamically regenerated based on existing stub files (supports third-partypackages)
Automated tests passed(43 tests)