Skip to content

Code style: _bedrock.py without comments, its markdown parser in steps - #93

Merged
utkarsh5026 merged 1 commit into
mainfrom
code-style-bedrock
Oct 18, 2026
Merged

utkarsh5026 merged 1 commit into
mainfrom
code-style-bedrock

Conversation

@utkarsh5026

Copy link
Copy Markdown
Owner

Step 3 of the code style work, for _bedrock.py, the module bedrock_kb.py and bedrock_chat.py share (after #90–#92).

What changed

Comments. All 90 # comments are gone:

  • Price tables: where the prices were read, when, and what each key means are now in the module docstring.
  • Dataclass fields: each class's fields are described in its docstring (KBDocument, Passage, Citation, ModelInfo, SavedFileList, _Json, _Answer).
  • The rest moved into the docstrings of the functions they explained.

Long functions split into steps:

Before After
_md_blocks: complexity 17, 75 lines a loop over _md_block, which hands each kind of block to its reader: _md_code, _md_quote, _md_table (with _md_align), _md_list and _md_paragraph
_Markdown.parse: complexity 19 _inline_at, which hands each kind of inline markup to _code_span, _emphasis_node, _link_node, _autolink or _bare_url
_Markdown.link: complexity 12 _md_closing_bracket and _md_link_target_after
parse_models: complexity 11 _is_text_model, _served_models, _model_info (with _profile_preference) and _application_profile_model
_conditions: complexity 11 _operator_conditions for (operator, *values)

_bedrock.py comes off both allowance lists.

Nothing a user sees changed

  • A differential test of old against new. main's _bedrock.py and this branch's gave byte-identical output on all of these:
    • 4,000 generated markdown answers (headings, lists nested in quotes, fences, tables, emphasis, links, bare URLs, escapes, raw HTML, javascript: links) with random citations: the HTML, the text lines and the [n] markers, 2.2 MB in all;
    • every where= form and its error messages;
    • parse_models across three regions, with profiles listed, unlisted and empty.
  • Tests: CI on 3.10 passes, with 1,164 passed and rules at 0 errors. The full suite on 3.13 passes, with 1,180 passed.
  • Reports: snapshot.py compare shows 319 of 321 outputs identical. The other two are the known traceback line numbers, the only "lost" names are the two from Code style: agent/ without comments, its tools as methods #92, and the AWS operations are unchanged.

No CHANGELOG entry: nothing a user sees changes.

🤖 Generated with Claude Code

Every # comment in _bedrock.py is gone: the price tables' sources and keys are in the module docstring, each
dataclass's fields in its docstring (KBDocument, Passage, Citation, ModelInfo, SavedFileList, _Json, _Answer), and
the rest in the docstrings of the functions they explained.

The functions over ruff's limits are split into steps:
- _md_blocks is a loop over _md_block, which hands each kind of block to its reader: _md_code, _md_quote,
  _md_table (with _md_align), _md_list and _md_paragraph.
- _Markdown.parse hands each kind of inline markup to _inline_at: _code_span, _emphasis_node, _link_node,
  _autolink and _bare_url; link() finds its brackets with _md_closing_bracket and _md_link_target_after.
- parse_models reads as _is_text_model, _served_models, _model_info (with _profile_preference) and
  _application_profile_model; _conditions hands (operator, *values) to _operator_conditions.

Old and new give byte-identical output on 4,000 generated markdown answers with random citations (HTML, text
lines and [n] markers), every where= form and its errors, and parse_models across regions and profile lists.
_bedrock.py is off ruff.toml's per-file-ignores and tests/test_style.py's comment allowances.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@utkarsh5026
utkarsh5026 merged commit fae638d into main Oct 18, 2026
8 checks passed
@utkarsh5026
utkarsh5026 deleted the code-style-bedrock branch October 18, 2026 06: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.

1 participant