Skip to content

Commit a9e8df7

Browse files
clementb49claude
andcommitted
fix: prevent crash in handle when accessible_output3 is unavailable
Introduce _NullAccessibleOutput with no-op speak/braille methods and assign it instead of None when _AO3_AVAILABLE is False, so handle(..., force=True) can never crash with AttributeError on unsupported platforms. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent e2616d5 commit a9e8df7

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

basilisk/accessible_output.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
try:
1111
import accessible_output3.outputs.auto
1212

13-
_ao3_available = True
13+
_AO3_AVAILABLE = True
1414
except ImportError:
15-
_ao3_available = False
15+
_AO3_AVAILABLE = False
1616

1717
if TYPE_CHECKING:
1818
import accessible_output3.outputs.auto
@@ -25,6 +25,16 @@
2525
RE_SPEECH_STREAM_BUFFER = re.compile(rf"{COMMON_PATTERN}")
2626

2727

28+
class _NullAccessibleOutput:
29+
"""No-op fallback used when accessible_output3 is unavailable."""
30+
31+
def speak(self, text: str) -> None:
32+
pass
33+
34+
def braille(self, text: str) -> None:
35+
pass
36+
37+
2838
class AccessibleOutputHandler:
2939
"""Handles accessible output and streaming for screen readers.
3040
@@ -68,18 +78,18 @@ def clean_steps(self) -> list[tuple[re.Pattern | str]]:
6878
def use_accessible_output(self) -> bool:
6979
"""Check if accessible output is enabled and available."""
7080
return (
71-
_ao3_available and config.conf().conversation.use_accessible_output
81+
_AO3_AVAILABLE and config.conf().conversation.use_accessible_output
7282
)
7383

7484
@measure_time
7585
def _init_accessible_output(self, display_log: bool) -> None:
7686
"""Initialize the Accessible Output library."""
77-
if not _ao3_available:
87+
if not _AO3_AVAILABLE:
7888
if display_log:
7989
log.debug(
8090
"accessible_output3 is not available on this platform."
8191
)
82-
self._accessible_output = None
92+
self._accessible_output = _NullAccessibleOutput()
8393
return
8494
if not self.use_accessible_output:
8595
if display_log:

0 commit comments

Comments
 (0)