Skip to content

[jit] Tuple and NamedTuple does not participate in type refinements #23049

@wanchaol

Description

@wanchaol
def test_named_tuple_type_refinement(self):
        from typing import List, Dict, Optional, Tuple
        class MyCoolNamedTuple(NamedTuple):
            a : int
            b : float
            c : Optional[int]

        @torch.jit.script
        def foo(x: MyCoolNamedTuple) -> int:
            if x.c is not None:
                return x.c
            else:
                return -1

            mnt = MyCoolNamedTuple(42, 420.0, 42)
            self.assertEqual(foo(mnt), mnt.c)

This does not work currently.

cc @suo

Metadata

Metadata

Assignees

No one assigned

    Labels

    jit-backlogoncall: jitAdd this issue/PR to JIT oncall triage queue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions