Skip to content

Conversation

@hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Oct 2, 2019

This PR fixes #25801 (see there for my verbose analysis).

As an example, for the following code:

import torch

@torch.jit.script
def f1(x):
    # type: (int, int) -> None
    pass

this PR will change error message from this:

RuntimeError:
Number of type annotations (2) did not match the number of function parameters (1):
# type: (int, int) -> None

to this:

RuntimeError:
Number of type annotations (2) did not match the number of function parameters (1):
at __scratch__/example.py:4:0
@torch.jit.script
def f1(x):
~~~~~~~~ <--- HERE
    # type: (int, int) -> None
    pass

@hi-ogawa hi-ogawa requested a review from apaszke as a code owner October 2, 2019 01:37
@pytorchbot pytorchbot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Oct 2, 2019
def build_def(ctx, py_def, type_line, self_name=None):
body = py_def.body
r = ctx.make_range(py_def.lineno, py_def.col_offset,
r = ctx.make_range(py_def.lineno + len(py_def.decorator_list),
Copy link
Contributor Author

@hi-ogawa hi-ogawa Oct 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this change, the error highlight gets one line off, like:

RuntimeError:
Number of type annotations (2) did not match the number of function parameters (1):
at __scratch__/example.py:4:0
@torch.jit.script
~~~~~~~~~~~~~~~~~ <--- HERE
def f1(x):
    # type: (int, int) -> None
    pass

Essentially this changes SourceRange of Decl (and also Def) so that it excludes decorator lines.
As far as I can tell, SourceRange is only used for error reporting, so I thought this change is appropriate.
But, maybe I'm missing something (since I only grepped e.g. def.range or decl.range), so it would be great if someone could assess the effect of this change.

@hi-ogawa
Copy link
Contributor Author

hi-ogawa commented Oct 2, 2019

It seems python test code doesn't pass linter. I'll handle that.

@hi-ogawa
Copy link
Contributor Author

hi-ogawa commented Oct 2, 2019

Flake8 lint error is fixed now.

Copy link
Contributor

@driazati driazati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long delay in reviewing, but this looks good! The test failures all seem flaky so this is good to land once the nit comment is addressed.

Thanks for the fix!

}

TreeRef parseClass() {
TreeRef parseClass() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spurious whitespace, please revert

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry about that. I reverted this change.

@hi-ogawa
Copy link
Contributor Author

@driazati Thanks so much for reviewing! One question though. Can I squash my commits into single commit and also rebase it to latest master?

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@driazati has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@driazati
Copy link
Contributor

You shouldn't have to, our landing process will squash and rebase the whole PR automatically

@hi-ogawa
Copy link
Contributor Author

@driazati Wow, that's cool, I didn't know that. So, maybe nothing more I need to do here. I'll leave it to you then. Thanks!

@facebook-github-bot
Copy link
Contributor

@driazati merged this pull request in 97b39a2.

thiagocrepaldi pushed a commit to thiagocrepaldi/pytorch that referenced this pull request Feb 4, 2020
Summary:
This PR fixes pytorch#25801 (see there for my verbose analysis).

As an example, for the following code:

```
import torch

torch.jit.script
def f1(x):
    # type: (int, int) -> None
    pass
```

this PR will change error message from this:

```
RuntimeError:
Number of type annotations (2) did not match the number of function parameters (1):
# type: (int, int) -> None
```

to this:

```
RuntimeError:
Number of type annotations (2) did not match the number of function parameters (1):
at __scratch__/example.py:4:0
torch.jit.script
def f1(x):
~~~~~~~~ <--- HERE
    # type: (int, int) -> None
    pass
```
Pull Request resolved: pytorch#27195

Differential Revision: D17910902

Pulled By: driazati

fbshipit-source-id: af5c6353069d005752d6c7f0bd6a0c6db8437e55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged oncall: jit Add this issue/PR to JIT oncall triage queue open source

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[jit] Missing source highlight error

6 participants