Skip to content

Add native Python symbol resolution - #815

Open
jonathan343 wants to merge 4 commits into
feat/codegen-selection-arenafrom
feat/codegen-symbols
Open

jonathan343 wants to merge 4 commits into
feat/codegen-selection-arenafrom
feat/codegen-symbols

Conversation

@jonathan343

@jonathan343 jonathan343 commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Note

Stacked on #814, targeting feat/codegen-selection-arena so this PR contains only the symbol-provider work and a small identifier-parser fix.

Summary

Adds SymbolProvider to turn selected Smithy shapes into Python declaration names, field/constant names, and immutable type references. It applies service renames, preserves acronyms, reports naming collisions, and handles recursive types and sparse collections. Enum values resolve to str/int to allow future service values.

Also fixes the loader rejecting valid identifiers such as _2HTTPServer, verified against Smithy CLI. The API and examples are in designs/codegen/symbols.md.

Example

Given a loaded model and its selection, with an HTTPResponse structure containing a statusCode integer field:

from smithy_python.symbols import SymbolProvider

symbols = SymbolProvider(model, selection, package="example.client")

symbols.declaration_name("example#HTTPResponse")        # "HTTPResponse"
symbols.member_name("example#HTTPResponse$statusCode")  # "status_code"
symbols.type_reference("smithy.api#Integer")            # TypeReference("int", "builtins")

Additional Testing

All 434 models in aws/api-models-aws passed independent checks of names, type references, nested arguments, module identity, and sparse nullability: 119,324 type references and 232,207 field targets checked. The 61 streaming references produced the expected unsupported diagnostic. These models contain no service renames; targeted tests cover those. This validation is local, not a CI dependency.


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

| __init__ | Init | init | INIT |
| class | Class | class_ | CLASS |
| None | None_ | none | NONE |
| match | Match | match | MATCH |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

these could be aligned using a markdown formatter for reading source mode

"members": {"statusCode": {"target": "smithy.api#Integer"}}
}
}
}''')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

will dynamic client generation be from this loaded model?

nullable: bool = False


_PRIMITIVES = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

primitive in what sense?

some of these are not fixed-length data, like string, int, big numbers, document.

if this is the set of smithy simple types, it should be called that instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe _FIXED_TYPES? not the smithy simple set, but types that have a non-composite/generic python representation

Map selected Smithy shapes to Python names and immutable type references. Apply service renames, detect normalized-name collisions, and resolve recursive types without recursive traversal.
Match Smithy identifier rules for shape names, members, and namespace segments. Keep rejecting names that start with a digit or contain only underscores.
Explain naming and type references with concrete examples. Cover valid underscore-prefixed numeric names in symbol tests.
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.

2 participants