Skip to content

Remove dead code and unused helper functions#7

Merged
sripathikrishnan merged 1 commit into
mainfrom
claude/cleanup-extradoc-dead-code-9p0Le
Feb 8, 2026
Merged

Remove dead code and unused helper functions#7
sripathikrishnan merged 1 commit into
mainfrom
claude/cleanup-extradoc-dead-code-9p0Le

Conversation

@sripathikrishnan
Copy link
Copy Markdown
Contributor

Summary

This PR removes a significant amount of dead code and unused helper functions that were identified during code cleanup. These functions were either superseded by newer implementations, no longer called, or part of incomplete refactoring efforts.

Key Changes

Removed Functions

  • cmd_test() in __main__.py - Unused command wrapper
  • _calculate_table_cell_end_index() in block_diff.py - Unused table cell calculation
  • _diff_table_cells() in block_diff.py - Legacy table diffing method (replaced by _diff_table_structure)
  • _lcs_align() in block_diff.py - Unused LCS alignment utility
  • Paragraph.text_content() in desugar.py - Unused text extraction method
  • flatten_section() in desugar.py - Unused section flattening utility
  • Style conversion helpers in diff_engine.py:
    • _styles_to_text_style()
    • _full_run_text_style()
    • DiffOperation dataclass
    • _operation_to_request()
    • _generate_paragraph_insert()
    • _generate_special_insert()
    • _generate_table_insert()
    • _emit_cell_content()
    • _table_cell_starts()
    • _table_length()
    • _element_length()
  • Content calculation helpers in diff_engine.py:
    • _adjust_for_segment_end()
    • _calculate_content_length()
    • _get_element_text()

Updated Imports

  • Removed unused imports from diff_engine.py (json, Paragraph, SpecialElement, Table, TableCell)
  • Removed unused import from desugar.py (Any)
  • Cleaned up request_generators/__init__.py to remove exports of deleted functions

Configuration

  • Added empty [dependency-groups] section to pyproject.toml for PEP 735 compatibility

Impact

  • Reduces codebase complexity and maintenance burden
  • Eliminates confusion from multiple implementations of similar functionality
  • No functional changes to active code paths
  • All removed code was either unreachable or superseded by newer implementations

https://claude.ai/code/session_01N8TnRLa3jk8RQWYhT3wb7H

Systematic dead code cleanup identified via vulture analysis and manual
call-graph tracing from the entry points (pull/diff/push/test in __main__.py).

Removed across 14 files:
- diff_engine.py: Legacy DiffOperation class and entire unused insert chain
  (_generate_paragraph_insert, _generate_special_insert, _generate_table_insert,
  _emit_cell_content, _table_cell_starts, _table_length, _element_length,
  _operation_to_request, _full_run_text_style, _styles_to_text_style,
  _adjust_for_segment_end, _calculate_content_length, _get_element_text)
- block_diff.py: Unused methods (_calculate_table_cell_end_index,
  _diff_table_cells, _lcs_align)
- request_generators/content.py: Entire file gutted (generate_content_requests
  and all supporting code never called from production)
- request_generators/structural.py: Unused functions (separate_structural_requests,
  extract_created_ids, substitute_placeholder_ids, CREATION_REQUEST_TYPES)
- request_generators/table.py: Unused functions (generate_table_cell_style_requests,
  calculate_cell_positions, calculate_table_length, generate_insert_table_request)
- style_converter.py: NAMED_STYLE_MAP, build_text_style_request,
  build_paragraph_style_request
- style_factorizer.py: extract_paragraph_style
- style_hash.py: style_id_short, __main__ demo block
- desugar.py: flatten_section, Paragraph.text_content
- xml_converter.py: _indent, _convert_footnote, current_tab_id field
- transport.py: Unused instance attributes (_access_token, _timeout)
- __main__.py: cmd_test (handled inline)

All 45 passing tests remain passing. The one pre-existing test failure
(test_table_cell_modified) is unrelated.

https://claude.ai/code/session_01N8TnRLa3jk8RQWYhT3wb7H
@sripathikrishnan sripathikrishnan merged commit 5f7698c into main Feb 8, 2026
1 check passed
sripathikrishnan added a commit that referenced this pull request Feb 27, 2026
Security:
- Move session_token from POST body to Authorization: Bearer header to prevent
  proxy/access log exposure (#1)
- Atomic ownership check in revoke_session_token via expected_email param,
  eliminating TOCTOU race (#2)
- Redact full session_hash from list_sessions when admin views another user's
  sessions; self-service callers retain it (#3)
- Fix X-Forwarded-For to use rightmost (infra-injected) IP instead of
  first (spoofable) entry (#7)

Correctness:
- Ensure service account is provisioned at session establishment time
  (exchange_auth_code_for_session), enforcing the invariant that SA always
  exists for any v2 session; remove downstream or-"" fallbacks and 500 guard (#6)
- Validate _server_base_url before opening browser to avoid post-auth failure
  when server URL is not configured (#4)
- Raise ValueError instead of silently dropping extra scopes in v2
  get_oauth_token (#5)
- Apply SA_TOKEN_CACHE_SECONDS cap client-side for SA tokens (#8)

UX:
- Prompt for confirmation before revoking an existing valid session in
  auth login; skip prompt when stdin is not a tty (#9)
- Use timezone.utc in all datetime.fromtimestamp calls in CLI output (#10)

Fakes / tests:
- Fix FakeDatabase.retrieve_auth_code to check flow_type and expiry before
  popping, preventing silent code destruction on type mismatch (#11)
- Update FakeDatabase.revoke_session_token to accept expected_email (#2)

Docs:
- Fix stale pseudo_scope field name in database.py docstring (#12)
- Document _explicit_auth_urls v2 activation edge case (#13)
- Add type safety / None discipline principle to CLAUDE.md files

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

2 participants