Skip to content

Add type hints to parsers#993

Draft
GlassOfWhiskey wants to merge 2 commits into
mainfrom
typed-python-parsers
Draft

Add type hints to parsers#993
GlassOfWhiskey wants to merge 2 commits into
mainfrom
typed-python-parsers

Conversation

@GlassOfWhiskey

Copy link
Copy Markdown
Contributor

This commit enables type hints within Python generated parsers. by refactoring how the codegen logic handles instance types. Results are fully-typed Python objects ready to be compiled with mypyc.

@codecov

codecov Bot commented Dec 19, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.52174% with 158 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.23%. Comparing base (4d95aa7) to head (1be191e).

Files with missing lines Patch % Lines
src/schema_salad/metaschema.py 73.76% 91 Missing and 26 partials ⚠️
src/schema_salad/python_codegen_support.py 0.00% 37 Missing ⚠️
src/schema_salad/python_codegen.py 97.18% 0 Missing and 2 partials ⚠️
src/schema_salad/runtime.py 87.50% 0 Missing and 1 partial ⚠️
src/schema_salad/tests/test_python_codegen.py 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #993      +/-   ##
==========================================
- Coverage   71.73%   71.23%   -0.51%     
==========================================
  Files          53       53              
  Lines        9957    10159     +202     
  Branches     2061     2093      +32     
==========================================
+ Hits         7143     7237      +94     
- Misses       2261     2358      +97     
- Partials      553      564      +11     

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@GlassOfWhiskey
GlassOfWhiskey force-pushed the typed-python-parsers branch 2 times, most recently from 33bb828 to a8947d0 Compare December 20, 2025 21:08
@GlassOfWhiskey
GlassOfWhiskey force-pushed the typed-python-parsers branch 6 times, most recently from 4f2c146 to cc5d220 Compare April 5, 2026 20:53
@GlassOfWhiskey
GlassOfWhiskey force-pushed the typed-python-parsers branch 5 times, most recently from 3883246 to 09cfc31 Compare June 29, 2026 17:34
Comment thread src/schema_salad/python_codegen.py Outdated

ext = ", ".join(parents) if parents else "Saveable"
self.out.write(
fmt(f"@mypyc_attr(native_class=True)\nclass {classname}({ext}):\n pass", 0)[:-9]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why @mypyc_attr(native_class=True)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To ensure it is actually compiled succesfully by mypyc, and to intercept potential regressions in the future

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I recommend @mypyc_attr(native_class=True, allow_interpreted_subclasses=True) to allow for subclassing

@GlassOfWhiskey
GlassOfWhiskey force-pushed the typed-python-parsers branch 2 times, most recently from 5dcde48 to 2ef29fc Compare July 15, 2026 16:56
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