fix(python): Sandbox.hibernate and Sandbox.shutdown classmethod shadows instance method#102
Open
Dev-X25874 wants to merge 2 commits into
Conversation
… shutdown→shutdown_by_id
…ate/shutdown resolve as instance methods
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.
In Python, a
@classmethoddefined after an instance method of the same namesilently replaces it in the class
__dict__. TheSandboxclass definedasync def hibernate(self)andasync def shutdown(self)as instance methods,then redefined both as
@classmethodfactories further down in the same classbody. The classmethods won, making the instance methods unreachable.
Any call to
await sandbox.hibernate()orawait sandbox.shutdown()on a liveSandboxinstance dispatched to the classmethod, which then raised:The TypeScript SDK avoids this naturally —
staticand instance methods occupyseparate 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
TestSandboxLifecycleMethodsintests/test_utils.pyusinginspect.getattr_staticto assert the resolution at class-definition time,so this can never silently regress again.