{{ message }}
fix: raise a clear TypeError when convert() is given a non-str - #274
Open
Thorsrud22 wants to merge 1 commit into
Open
Thorsrud22 wants to merge 1 commit into
Thorsrud22 wants to merge 1 commit into
Conversation
Thorsrud22
force-pushed
the
reject-non-str-input
branch
from
September 11, 2026 16:36
6eb43de to
1d79f46
Compare
Passing a list of lines to Ansi2HTMLConverter.convert() (or prepare()) used to fail deep inside the regex pass with "AttributeError: 'list' object has no attribute 'replace'", which gives no hint about what was wrong or how to fix it. Two users reported hitting this (pycontribs#242). Check the input type once at the entry point and raise a TypeError that names the actual type and suggests joining the lines first. Fixes pycontribs#242 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Thorsrud22
force-pushed
the
reject-non-str-input
branch
from
September 13, 2026 18:56
1d79f46 to
688afb6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #242.
Passing a list of lines to
Ansi2HTMLConverter.convert()currently fails deep inside the regex pass withAttributeError: 'list' object has no attribute 'replace', which says nothing about what went wrong. Two people reported hitting it, and the reporter's own workaround ("".join(ansi)) shows what the input actually was.This adds a single
isinstancecheck at the top ofprepare()(the common path for bothconvert()andprepare()) and raises:Behaviour for
strinput is unchanged. A regression test is included.Verified locally: all 42 tests pass, and the isort, black, flake8, pylint and mypy pre-commit hooks pass on the changed files.
🤖 Generated with Claude Code