Skip to content

Fix unformatted f-string in List type error message#1870

Merged
RobinPicard merged 2 commits into
dottxt-ai:mainfrom
tan7vir:fix/list-error-message-fstring
Jun 19, 2026
Merged

Fix unformatted f-string in List type error message#1870
RobinPicard merged 2 commits into
dottxt-ai:mainfrom
tan7vir:fix/list-error-message-fstring

Conversation

@tan7vir

@tan7vir tan7vir commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

What

_handle_list in outlines/types/dsl.py raises a TypeError when a List
type is given the wrong number of arguments. The message was built from two
adjacent string literals, and the second one was a plain string rather than an
f-string:

raise TypeError(
    "Only homogeneous lists are supported. You should provide exactly "
    + "one argument to `List`, got {args}."
)

So {args} was printed literally instead of the actual arguments. For example
List[int, str] produced:

Only homogeneous lists are supported. You should provide exactly one argument to `List`, got {args}.

The sibling _handle_dict a few lines down already uses an f-string
(f"Dict must have exactly two type arguments. Got {args}."), so this just
brings _handle_list in line with it.

After

Only homogeneous lists are supported. You should provide exactly one argument to `List`, got (<class 'int'>, <class 'str'>).

Tests

test_dsl_handle_list already exercised this path with a bare
pytest.raises(TypeError), which passed even with the broken message. I
tightened that assertion to match the interpolated args so it fails on the
old string and passes on the fix.

tan7vir and others added 2 commits June 3, 2026 15:08
The error raised by `_handle_list` for an invalid number of type
arguments used a plain string literal, so the `{args}` placeholder was
printed verbatim instead of the offending arguments. Make it an f-string
so the message reports the actual args, matching the sibling
`_handle_dict` error.

Also tighten the existing test to assert the args are interpolated.
@RobinPicard RobinPicard merged commit b500d7e into dottxt-ai:main Jun 19, 2026
3 of 6 checks passed
@RobinPicard

Copy link
Copy Markdown
Contributor

Thanks for the fix!

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