← Back to Pull requests

Add thriftpy2.load_str #414

Open
hippi345 opened this pull request with 59 lines diff across 3 files
View on GitHub
hippi345 hippi345 commented on Oct 30, 2026 15:51 UTC
Author

Adds thriftpy2.load_str(source, module_name). It wraps parse_fp with io.StringIO, registers the module in sys.modules the same way load_fp does, and is exported next to load and load_fp. Also adds test_load_str and a CHANGES entry.

mod = thriftpy2.load_str("struct Foo { 1: string bar, }", "foo_thrift")

The new test passes. Locally, the parser and loader tests give 62 passed and 2 errors. Both errors are in sub-thread tests that need a reraise fixture, and they also fail on master.

Closes #290

Diff: 59 lines (+56 / -3) across 3 files Reviewer: aisk Review duration: 26634m
All Vouch review confidence checks passed
Residual risk 0.03 = Change Risk (0.35) × (1 − Review Confidence (0.91)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.35 · 59 lines diff across 3 files
0.35
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.94 · 2 substantive comment(s)
0.94
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
90%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.245
Ai Authored ai_authored
0.050
Real PR Conversation Timeline
3 items
aisk aisk commented on code on Oct 31, 2026 09:54 UTC
Code Review
CHANGES.rst:1
@@ -4,6 +4,10 @@ Changelog
 .. note::
    Future release notes will be available at https://github.com/Thriftpy/thriftpy2/releases
 
+- Add ``load_str`` API to load thrift IDL from a string, via `#290`_.

CHANGES.rst is no longer maintained (release notes now live in GitHub Releases), please remove this change.

aisk aisk commented on code on Oct 31, 2026 10:04 UTC
Code Review
thriftpy2/parser/__init__.py:1
@@ -74,6 +75,14 @@ def load_fp(source: TextIO, module_name: str) -> types.ModuleType:
     return thrift
 
 
+def load_str(source: str, module_name: str) -> types.ModuleType:
+    """Load thrift IDL from a string as a module.
+    """
+    thrift = parse_fp(io.StringIO(source), module_name)

Could you add an enable_cache param defaulting to False? The cache is keyed by module_name only and shared with load(), so loading a different string under the same name silently returns the old module.

Reviewers
Assignees
hippi345 hippi345
Labels
risk: low confidence: 90.9% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 35.4% (MEDIUM) · Higher = larger blast radius
35.4%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 90.9% · Lower = rushed or shallow review
90.9%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 3.2% · Safe to merge
3.2%