← Back to Pull requests

[lexical-mdast] Bug Fix: Leave a typed __init__ as text instead of a bold word #9921

Closed
unknown closed this pull request without merging on Nov 16, 2026 17:00 UTC
View on GitHub
unknown unknown commented on Nov 15, 2026 20:12 UTC
Author

Description

With MdastShortcutsExtension, typing a Python name such as __init__ or __main__ in a sentence deletes the underscores and bolds the word as the closing __ is typed, so "Edit the __init__ file" reads "Edit the init file".

The typed shortcut converts whatever construct micromark sees closing at the caret, and CommonMark reads __init__ as strong emphasis around init. Import has to read it that way, but in prose a __ run around a single word of ASCII letters, digits and underscores is more often a name than a bold word; snake_case and x__init__ already stay as typed because _ runs don't open inside a word.

MarkdownStreamScanner.scanInline now leaves strong emphasis alone when its delimiters are __ and it holds one such word. init, __two words__ and _init_ still convert, and Markdown import is unchanged. A writer who wants one bold word types word or uses the bold command. Only the construct that closes at the caret is checked, so a name inside another construct, such as the __init__, still loses its underscores when the outer delimiter is typed, as it does on main.

Test plan

Before

The new tests on main:

$ pnpm exec vitest run --project unit packages/lexical-mdast/src/__tests__/unit/MdastShortcuts.test.ts -t "run around one name|still converts"
 × a `__` run around one name leaves the __init__ as text
   → expected 'the init' to be 'the __init__' // Object.is equality
 × a `__` run around one name leaves __main__ as text
   → expected 'main' to be '__main__' // Object.is equality
 × a `__` run around one name leaves obj.__init__ as text
   → expected 'obj.init' to be 'obj.__init__' // Object.is equality
 × a `__` run around one name leaves __my_var__ as text
   → expected 'my_var' to be '__my_var__' // Object.is equality
 ✓ **init** still converts
 ✓ __two words__ still converts
 ✓ _init_ still converts
 ✓ a fence indented up to three spaces still converts
      Tests  4 failed | 4 passed | 53 skipped (61)

After

$ pnpm run test-unit
 Test Files  987 passed | 6 skipped (993)
      Tests  39734 passed | 423 expected fail | 174 skipped (40331)

The new tests also check that the typed text exports with its underscores escaped (the \_\_init\_\_). pnpm run ci-check (TypeScript, Flow, Prettier, ESLint and the changeset check) passes. Not run in a browser: the change is in the scanner the typed shortcut calls, which these tests drive one typed character at a time.

Diff: 313 lines (+234 / -79) across 3 files Reviewer: potatowagon Review duration: 1247m
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 313 lines diff across 3 files
0.40
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
60%
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.344
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #9921"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 60.5% 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: 40.3% (MEDIUM) · Higher = larger blast radius
40.3%
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: 60.5% · Lower = rushed or shallow review
60.5%
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: 15.9% · Safe to merge
15.9%
Repository