Skip to content

Bug: isinstance with tuple of types produces incorrect output #26

@swernerx

Description

@swernerx

Description

When using isinstance() with a tuple of types (common Python pattern), the output is incorrect.

Python Input

if isinstance(obj, (list, tuple, dict)):
    pass

Current Output (v1.3.1)

if (isinstance(obj, tuple(list, tuple, dict))) {
}

Problem

tuple(list, tuple, dict) calls the tuple function with three arguments, which is wrong. The Python tuple here is just a literal grouping of types.

Expected Output (Option A - Direct translation)

if (isinstance(obj, [list, tuple, dict])) {
}

Expected Output (Option B - Native JS)

if (Array.isArray(obj) || obj instanceof Set || obj instanceof Map) {
}

Test Case

# Multiple type check
isinstance(x, (int, float, complex))

# Single type check (works correctly)
isinstance(x, int)

Priority

🟡 Medium - Common pattern in Python code

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions