Skip to content

[jit] Spurious error when type comments are found in the body of a function. #30477

@suo

Description

@suo

Repro:

@torch.jit.script
class Timebase:
    def __init__(
        self,
        numerator,  # type: int
        denominator,  # type: int
    ):
        # type: (...) -> None
        self.numerator = numerator  # type: int
        self.denominator = denominator  # type: int

Produces the error:

RuntimeError: Return type line '# type: (...) -> ...' not found on multiline type annotation
(See PEP 484 https://www.python.org/dev/peps/pep-0484/#suggested-syntax-for-python-2-7-and-straddling-code)

Even though we have clearly put the return type comment in the function. This is due to a bug in the type comment parser, which expects the return type line to be the last element of the list (see here).

Fix is simple, just search for the return type line instead of assuming it's the last one.

cc @suo

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueoncall: jitAdd this issue/PR to JIT oncall triage queuetriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions