Skip to content

Add type hints to parsers#993

Draft
GlassOfWhiskey wants to merge 1 commit into
mainfrom
typed-python-parsers
Draft

Add type hints to parsers#993
GlassOfWhiskey wants to merge 1 commit 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 82.77512% with 72 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.55%. Comparing base (ee603d4) to head (09cfc31).

Files with missing lines Patch % Lines
src/schema_salad/python_codegen_support.py 0.00% 39 Missing ⚠️
src/schema_salad/metaschema.py 89.59% 19 Missing and 12 partials ⚠️
src/schema_salad/python_codegen.py 98.59% 0 Missing and 1 partial ⚠️
src/schema_salad/runtime.py 80.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #993      +/-   ##
==========================================
- Coverage   71.58%   71.55%   -0.04%     
==========================================
  Files          53       53              
  Lines        9912     9978      +66     
  Branches     2058     2057       -1     
==========================================
+ Hits         7096     7140      +44     
- Misses       2264     2290      +26     
+ Partials      552      548       -4     

☔ 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 4 times, most recently from 114f0fd to 3883246 Compare June 29, 2026 17:29

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

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