Skip to content

feat(code_generation): add split_scalar_type_aliases helper - #16

Merged
phil65 merged 1 commit into
mainfrom
feat/split-scalar-type-aliases
Nov 27, 2026
Merged

phil65 merged 1 commit into
mainfrom
feat/split-scalar-type-aliases

Conversation

@phil65

@phil65 phil65 commented Nov 27, 2026

Copy link
Copy Markdown
Owner

Adds split_scalar_type_aliases(source, *, types_module, header=None) -> SplitTypeAliasesResult in schemez.code_generation.type_splitter (re-exported from schemez.code_generation and schemez).

Purpose

Schema-generated modules (e.g. from datamodel-codegen) mix lightweight Literal / scalar type aliases with hundreds of Pydantic BaseModel classes. Extracting those pure scalar/literal aliases into a sibling leaf module allows downstream libraries (especially with Python 3.15 PEP 810 __lazy_modules__) to import them without paying the import cost of the full model module or risking manual type drift.

What it handles

  • PEP 695 type X = ..., X: TypeAlias = ..., and plain Literal/Annotated/union aliases
  • Fixed-point transitive selection of aliases referencing other extracted aliases (topologically ordered, preserving original definition order as tie-breaker)
  • Annotated[scalar, Field(...)] with constant arguments (only imports pydantic.Field when needed)
  • Preserves immediately-following attribute docstrings
  • Rewrites the original module to remove extracted declarations and import them back from types_module

@codecov

codecov Bot commented Nov 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.55556% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.05%. Comparing base (d3f50d7) to head (583dd2b).

Files with missing lines Patch % Lines
src/schemez/code_generation/type_splitter.py 87.38% 28 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #16      +/-   ##
==========================================
+ Coverage   69.00%   70.05%   +1.05%     
==========================================
  Files          40       41       +1     
  Lines        3678     3901     +223     
==========================================
+ Hits         2538     2733     +195     
- Misses       1140     1168      +28     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@phil65
phil65 merged commit 986052b into main Nov 27, 2026
16 of 22 checks passed
@phil65
phil65 deleted the feat/split-scalar-type-aliases branch November 27, 2026 23:38
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