Migrate constructor/factory methods to MyType.factory.my_method#105
Open
rjhuijsman wants to merge 3 commits into
Open
Migrate constructor/factory methods to MyType.factory.my_method#105rjhuijsman wants to merge 3 commits into
MyType.factory.my_method#105rjhuijsman wants to merge 3 commits into
Conversation
Before this change, constructors lived directly on the state class: a user-defined constructor named `ref` silently collided with the built-in `MyType.ref()`, and the framework could never add a new factory method without risking a clash with an existing user constructor — which a customer could not rename or delete, leaving them permanently unable to upgrade. This commit namespaces every state type's constructor (a.k.a. factory) methods under a `factory` attribute, so `await MyType.create(context)` becomes `await MyType.factory.create(context)`. That frees the top level of the generated state class for framework methods we may want to add later (e.g. a future `MyType.query(...)`), and prevents naming collisions with built-in methods. The way a constructor is declared (`factory=True`, or the `constructor` proto option) is unchanged; only the call surface moved. IMPORTANT REVIEWER HINT: the GitHub diff of the `*.j2` files is big, but very little actually changed: a bunch of methods got indented inside a new `_Factory` class, that's it. For Python that's literally just 4 spaces added to everything, for TS some code had to move to be contiguous but still remains unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xyvD8vLQ9dTwtFMexovJo
The `upgrade` skill rolls fragments from `skills/upgrade/migrations/next/` into each release's migration notes. This adds the fragment for the constructor-namespacing change so an app upgrading past it knows to move its constructor calls: it gives grep-able before/after patterns for `Foo.create(context, ...)` -> `Foo.factory.create(context, ...)`, plus the idempotency-scope and custom-constructor variants. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xyvD8vLQ9dTwtFMexovJo
The previous commit changed where constructor/factory methods live; this commit changes all the callers to use the new syntax. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011xyvD8vLQ9dTwtFMexovJo
Current Aviator status
This PR is not ready to merge (currently in state pending): this PR has not been approved. Pending Status Checks
See the real-time status of this PR on the
Aviator webapp.
Use the Aviator Chrome Extension
to see the status of your PR within GitHub.
|
|
This pull request can't be queued because it's currently a draft. |
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.
Fixes #106
Before this change, constructors lived directly on state classes (e.g.
Account.open()). A user-defined constructor namedrefwould have silently collided with the built-inMyType.ref(), and the framework could never add a new factory method without risking a clash with an existing user constructor — which a customer also can't rename or delete, leaving them permanently unable to upgrade.This PR namespaces every state type's constructor (a.k.a. factory) methods under a
factoryattribute, soawait MyType.create(context)becomesawait MyType.factory.create(context). That frees the top level of the generated state class for framework methods we may want to add later (e.g. a futureMyType.query(...)), and prevents naming collisions with built-in methods. How a constructor is declared (factory=True, or theconstructorproto option) is unchanged — only the call surface moved.Reviewer hint: the GitHub diff of the
*.j2template files looks big, but very little actually changed — it's ~all mechanical. In Python the constructor and idempotency-scope methods are simply indented into a new nestedclass _Factory(literally +4 spaces on everything). In TypeScript the same methods had to be moved to keep them contiguous. No control flow or logic changed in either language. The only "functional" changes are a new class to wrap these methods, and a.factoryin places they're called. The*.golden.*files are regenerated codegen output.I suggest you review the commits individually.