Conversation
Parametrized generics such as `set[int]`, `Set[int]` and `FrozenSet[str]` are `callable()` but are not a function or class signature. They therefore fell through to the callable branch in `python_types_to_terms` and raised a misleading `ValueError: Each argument must have a type annotation` instead of the intended `TypeError: Type ... is currently not supported` that their bare counterparts (`set`, `frozenset`) already raise. Gate the callable branch with `get_origin(ptype) is None` so parametrized generics skip it and reach the clear unsupported-type error. Add a regression test alongside the existing `bytes` assertion.
This branch has not been deployed
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.
What this does
python_types_to_termsraises a misleading error for unsupported parametrized set-like generics.The bare types already raise the intended, clear error:
Root cause
Parametrized generics like
set[int]arecallable()but are not a type (isinstance(set[int], type)isFalse), sois_callable(...)returnsTrue. They fall into the callable branch, which callsget_schema_from_signature(...)and raisesValueError: Each argument must have a type annotation— an error that has nothing to do with the actual problem (an unsupported container type).Fix
Gate the callable branch with
get_origin(ptype) is Noneso parametrized generics skip it and reach the clearTypeError: Type ... is currently not supportederror, matching the behavior of their bare counterparts.Testing
Added a regression test next to the existing
bytesassertion intest_dsl_python_types_to_terms, coveringset[int],Set[int],FrozenSet[str]andfrozenset[int]. It fails before the fix (with the misleadingValueError) and passes after.pytest tests/types/— 346 passedruff check --config=pyproject.toml(v0.9.1) — cleanmypy --allow-redefinition src/outlines/types/dsl.py— clean