Skip to content

Fix return type annotations for CellStyle properties in Python API#591

Merged
gnachman merged 1 commit intognachman:masterfrom
mkusaka:fix/screen-cellstyle-missing-return
Feb 24, 2026
Merged

Fix return type annotations for CellStyle properties in Python API#591
gnachman merged 1 commit intognachman:masterfrom
mkusaka:fix/screen-cellstyle-missing-return

Conversation

@mkusaka
Copy link
Contributor

@mkusaka mkusaka commented Feb 23, 2026

Summary

Fixed return type annotations for CellStyle.fg_color, bg_color, and URL.identifier to correctly reflect that they can return None.

Background

  • fg_color / bg_color dispatch on protobuf oneof fields via if/elif branches, but implicitly return None when none of the branches match
  • URL.identifier documents "or None if not set" in its docstring, but the return type was declared as str
  • Verified by connecting to a live iTerm2 instance: approximately 500 cells returned None for bg_color during normal screen display, confirming this is a practical issue

Verification

Confirmed that mypy --ignore-missing-imports iterm2/screen.py no longer reports Missing return statement [return] or Incompatible return value type [return-value].

CellStyle.fg_color, bg_color, and URL.identifier can return None when
protobuf oneof fields are unset, but their type annotations did not
reflect this. Change return types to Optional to match reality.

mypy flagged fg_color and bg_color as missing return statements
(screen.py:175, 191) and identifier as returning incompatible type
(screen.py:76).
@gnachman gnachman merged commit d3a2756 into gnachman:master Feb 24, 2026
1 check passed
@mkusaka mkusaka deleted the fix/screen-cellstyle-missing-return branch February 25, 2026 01:48
eyupcanakman pushed a commit to eyupcanakman/iTerm2 that referenced this pull request Mar 1, 2026
…n#591)

CellStyle.fg_color, bg_color, and URL.identifier can return None when
protobuf oneof fields are unset, but their type annotations did not
reflect this. Change return types to Optional to match reality.

mypy flagged fg_color and bg_color as missing return statements
(screen.py:175, 191) and identifier as returning incompatible type
(screen.py:76).
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