Skip to content

fix(python): Sandbox.hibernate and Sandbox.shutdown classmethod shadows instance method#102

Open
Dev-X25874 wants to merge 2 commits into
togethercomputer:mainfrom
Dev-X25874:fix/sandbox-classmethod-shadows-instance-hibernate-shutdown
Open

fix(python): Sandbox.hibernate and Sandbox.shutdown classmethod shadows instance method#102
Dev-X25874 wants to merge 2 commits into
togethercomputer:mainfrom
Dev-X25874:fix/sandbox-classmethod-shadows-instance-hibernate-shutdown

Conversation

@Dev-X25874

Copy link
Copy Markdown
Contributor

In Python, a @classmethod defined after an instance method of the same name
silently replaces it in the class __dict__. The Sandbox class defined
async def hibernate(self) and async def shutdown(self) as instance methods,
then redefined both as @classmethod factories further down in the same class
body. The classmethods won, making the instance methods unreachable.

Any call to await sandbox.hibernate() or await sandbox.shutdown() on a live
Sandbox instance dispatched to the classmethod, which then raised:

TypeError: hibernate() missing 1 required positional argument: 'sandbox_id'

The TypeScript SDK avoids this naturally — static and instance methods occupy
separate namespaces. Python has no equivalent distinction, so the two classmethod
factories are renamed to hibernate_by_id / shutdown_by_id.

  • await sandbox.hibernate() — instance method, restored ✓
  • await sandbox.shutdown() — instance method, restored ✓
  • await Sandbox.hibernate_by_id("id", api_key=...) — classmethod factory ✓
  • await Sandbox.shutdown_by_id("id", api_key=...) — classmethod factory ✓

Adds TestSandboxLifecycleMethods in tests/test_utils.py using
inspect.getattr_static to assert the resolution at class-definition time,
so this can never silently regress again.

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.

1 participant