{{ message }}
Repository navigation
fix(core): match converter source types without raw isinstance - #2310
Merged
rapids-bot[bot] merged 1 commit intoOct 15, 2026
Merged
rapids-bot[bot] merged 1 commit into
rapids-bot[bot] merged 1 commit into
Conversation
The type converter compared a registered source annotation against the incoming data with isinstance, which rejects valid annotations: typing.Any and typing.Literal raise TypeError, and a union containing a parameterized generic (dict[str, int] | None) raises 'isinstance() argument 2 cannot be a parameterized generic'. Registering a converter from any of those made the conversion fail, including conversions that did not reach that converter first. Both the direct and the indirect matching path now use DecomposedType.is_instance, the safe check this file already relies on for targets and parameterized generics. is_instance is also made safe for the same constructs: Literal constrains the value rather than the class, so it is matched against its arguments (type checked so True does not satisfy Literal[1]), and any other non-class root matches nothing instead of raising. Signed-off-by: CodeAlex52 <59381946+CodeAlex52@users.noreply.github.com>
Member
|
/ok to test 40bd53a |
willkill07
approved these changes
Oct 15, 2026
Member
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.

Description
A converter registered from a source annotation that
isinstancerejects could not be used. Theconverter compared the registered source type against the incoming data with a raw
isinstance:isinstancerejects several valid annotations:typing.AnyTypeError: typing.Any cannot be used with isinstance()typing.Literal["a"]TypeError: typing.Literal cannot be used with isinstance()dict[str, int] | None(union with a parameterized generic)TypeError: isinstance() argument 2 cannot be a parameterized genericstr | NoneThe same applies to the target side (
TypeConverter._convertandis_instance) and to theindirect path, which had its own union special case.
Fix
DecomposedType.is_instance, the safe check this file alreadydocuments for parameterized generics ("Use DecomposedType for safe isinstance check with
parameterized generics"), and the one the target side already uses. The ad-hoc union branches
are removed; a union is resolved member by member inside
is_instance.DecomposedType.is_instanceis made safe for the same constructs:Literal[...]constrains the value, not the class, so it is matched against its literalarguments with a type check (
Truedoes not satisfyLiteral[1], and vice versa).Tests
test_converter.py: sources registered fromAny,Literal["a"](match and no-match), anddict[str, int] | None(both members, direct and through an indirect chain), plus targets ofAnyandLiteral. All of these fail before the change.test_type_utils.py:is_instancewithLiteral(including thebool/intdistinction) andwith constructs that keep a non-class root (
NoReturn,Final[int]).Verification:
test_converter.py+test_type_utils.py→ 93 passed (87 before); reverting thesource change fails exactly the 6 new tests.
yapf --style ./pyproject.tomlandruff check(versions pinned in
.pre-commit-config.yaml) are clean.Note: this branch is based on
developbefore #2309, which also touchestype_utils.py(
is_subtype). The two changes are in different methods; I will rebase if #2309 lands first.Summary by CodeRabbit
Any, andLiteralannotations.Truedo not matchLiteral[1].