Skip to content

add lazy model generation - #863

Open
stobrien89 wants to merge 1 commit into
native-types-codegenfrom
native-model-codegen
Open

stobrien89 wants to merge 1 commit into
native-types-codegenfrom
native-model-codegen

Conversation

@stobrien89

Copy link
Copy Markdown
Contributor

Issue #, if available:
#797

Description

Adds native generation of lazy runtime models and typed model stubs for standalone types packages.

This PR is stacked on #857.

Changes

  • Emits models.py and models.pyi.
  • Supports structures, errors, unions, enums, defaults, and service renames.
  • Resolves cross-namespace targets using full shape IDs.
  • Preserves lazy construction, serde behavior, star imports, dir(), and pickling.
  • Adds Ruff and strict Pyright validation for generated models.

Follow-up work

  • Integrate schema and model generation into the types CLI pipeline.
  • Generate package metadata and supporting files.
  • Add Java/native parity and large-model tests.
  • Add schema and stub partitioning based on performance measurements.

Compatibility

Existing ModelRegistry callers remain supported. New runtime arguments are optional and backward compatible.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@stobrien89
stobrien89 added this pull request to stack #864 October 22, 2026 19:47
@stobrien89
stobrien89 requested a balanced review from Copilot October 22, 2026 19:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

5 open issues
What changed in this PR

Adds native generation for lazy runtime Smithy models (models.py) alongside full typing stubs (models.pyi), and updates import rendering to produce grouped/combined imports to support the new generated modules.

Changes:

  • Add ModelGenerator to emit lazy runtime model modules and .pyi stubs, including validation of reserved member names.
  • Update PythonWriter to render grouped/combined imports and adjust formatting for stub files.
  • Extend smithy-core ModelRegistry to support full shape-id target mappings for unambiguous renamed/cross-namespace target resolution.
File Description
packages/​smithy-python/​tests/​unit/​test_writer.py Updates import-format assertions and adds coverage for grouped/combined imports.
packages/​smithy-python/​tests/​unit/​test_models.py Adds end-to-end tests for generated runtime/stub models, plus Ruff/Pyright validation.
packages/​smithy-python/​src/​smithy_python/​writer.py Implements grouped/combined import rendering and stub-specific spacing.
packages/​smithy-python/​src/​smithy_python/​models.py Introduces model/stub generation for lazy runtime models.
packages/​smithy-python/​src/​smithy_python/​generation.py Extends ModelPlan to include registry metadata used by lazy model generation.
packages/​smithy-python/​src/​smithy_python/​files.py Marks .pyi writers as stubs to adjust formatting behavior.
packages/​smithy-python/​.changes/​next-release/​smithy-python-feature-model-generation.json Adds changelog entry for model generation feature.
packages/​smithy-core/​tests/​unit/​test_dynamic_models.py Adds tests for copied name maps and full shape-id target resolution.
packages/​smithy-core/​src/​smithy_core/​_dynamic_models.py Adds target_names support and improves rename handling during build/target resolution.
packages/​smithy-core/​.changes/​next-release/​smithy-core-enhancement-model-target-names.json Adds changelog entry for ModelRegistry target-name enhancement.

Review effort: Lite

Comment thread packages/smithy-python/src/smithy_python/writer.py Outdated
Comment thread packages/smithy-python/src/smithy_python/writer.py Outdated
Comment thread packages/smithy-python/tests/unit/test_models.py
Comment thread packages/smithy-python/tests/unit/test_models.py
Comment thread packages/smithy-python/tests/unit/test_writer.py

Copilot AI left a comment

Copy link
Copy Markdown

Comment thread packages/smithy-core/src/smithy_core/_dynamic_models.py
Comment thread packages/smithy-python/src/smithy_python/models.py
Comment thread packages/smithy-python/src/smithy_python/models.py Outdated
Comment thread packages/smithy-python/src/smithy_python/models.py Outdated
Comment thread packages/smithy-python/src/smithy_python/models.py
Comment thread packages/smithy-python/src/smithy_python/models.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread packages/smithy-core/src/smithy_core/_model_naming.py Outdated
Comment thread packages/smithy-python/src/smithy_python/models.py
Comment thread packages/smithy-python/src/smithy_python/symbols.py
Comment thread packages/smithy-core/src/smithy_core/_model_naming.py Outdated
Comment thread packages/smithy-python/src/smithy_python/models.py
@stobrien89
stobrien89 force-pushed the native-model-codegen branch from 191a6c8 to 4e3f735 Compare October 22, 2026 21:09
@stobrien89
stobrien89 requested a balanced review from Copilot October 22, 2026 21:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

No open issues 🎉

5 resolved since last review

Review effort: Lite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open issues

Review effort: Lite

Comment thread packages/smithy-python/src/smithy_python/models.py Outdated
Comment thread packages/smithy-python/src/smithy_python/writer.py
Comment thread packages/smithy-python/src/smithy_python/writer.py
Comment thread packages/smithy-python/tests/unit/test_writer.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread packages/smithy-core/src/smithy_core/_dynamic_models.py Outdated
Comment thread packages/smithy-python/src/smithy_python/models.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved model-identity collisions and sensitive-message exposure need correction before approval.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread packages/smithy-core/src/smithy_core/_dynamic_models.py
Comment thread packages/smithy-core/src/smithy_core/_dynamic_models.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved error classification, alias-cache collisions, naming compatibility, and stub nullability issues affect runtime correctness and the generated API.

4 open issues
2 resolved since last review

Review effort: Balanced

Comment thread packages/smithy-core/src/smithy_core/_dynamic_models.py Outdated
Comment thread packages/smithy-python/src/smithy_python/models.py
Comment thread packages/smithy-core/src/smithy_core/_model_naming.py Outdated
Comment thread packages/smithy-python/src/smithy_python/models.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved class-cache collisions and runtime/stub naming and export mismatches affect supported model APIs.

4 open issues
1 resolved since last review

Review effort: Balanced

Comment thread packages/smithy-core/src/smithy_core/_dynamic_models.py Outdated
Comment thread packages/smithy-python/src/smithy_python/models.py
Comment thread packages/smithy-python/src/smithy_python/models.py
Comment thread packages/smithy-python/src/smithy_python/models.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Shared runtime and cross-generator naming changes require human compatibility review, and a confirmed runtime correctness issue remains unresolved.

1 open issue
4 resolved since last review

Review effort: Balanced

Comment thread packages/smithy-python/src/smithy_python/symbols.py

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Shared runtime and Java naming changes need human compatibility review, with a blocking enum-naming defect still unresolved.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread packages/smithy-python/src/smithy_python/symbols.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Shared runtime naming and alias-resolution changes affect both generators, and full Java/native compatibility remains unverified.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@stobrien89
stobrien89 marked this pull request as ready for review October 23, 2026 16:53
@stobrien89
stobrien89 requested a review from a team as a code owner October 23, 2026 16:53
@stobrien89
stobrien89 force-pushed the native-model-codegen branch 2 times, most recently from 9499993 to ca5d954 Compare October 23, 2026 17:15
Comment thread codegen-output-py/types/src/example_types/models.py Outdated
@stobrien89
stobrien89 force-pushed the native-model-codegen branch from ca5d954 to 769018f Compare October 23, 2026 17:25
kuhe
kuhe previously approved these changes Oct 23, 2026
kuhe
kuhe previously approved these changes Oct 23, 2026
@stobrien89
stobrien89 force-pushed the native-model-codegen branch 2 times, most recently from 5f8e76f to 97a11c2 Compare October 24, 2026 00:01
@stobrien89
stobrien89 force-pushed the native-model-codegen branch from 97a11c2 to 4478983 Compare October 25, 2026 17:37
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.

3 participants