Skip to content

Conversation

@driazati
Copy link
Contributor

@driazati driazati commented Jun 4, 2019

This adds support for PEP 526 style annotations on assignments in place of
torch.jit.annotate(), so

a = torch.jit.annotate(List[int], [])

turns into

a : List[int] = []

Differential Revision: D15706021

This adds support for PEP 526 style annotations in place of
`torch.jit.annotate()`, so

```python
a = torch.jit.annotate(List[int], [])
a : List[int] = []
```
@pytorchbot pytorchbot added oncall: jit Add this issue/PR to JIT oncall triage queue module: pybind Related to our Python bindings / interactions with other Python libraries labels Jun 4, 2019
@driazati driazati changed the title [jit] Add support for type annotations [wip][jit] Add support for type annotations Jun 5, 2019
@ezyang ezyang added facebook and removed facebook labels Jun 5, 2019
@driazati driazati changed the title [wip][jit] Add support for type annotations [jit] Add support for type annotations Jun 6, 2019
@driazati driazati requested review from eellison and suo June 6, 2019 18:29
@driazati driazati changed the title [jit] Add support for type annotations [jit] Support for type annotations instead of torch.jit.annotate() Jun 6, 2019
@eellison
Copy link
Contributor

eellison commented Jun 6, 2019

Haven't looked very closely yet but could you add a test case for
x: List[int] = [0.5] ?
People will expect the annotations to have casting behavior but they don't

@driazati
Copy link
Contributor Author

driazati commented Jun 6, 2019

Added a test, mypy doesn't allow casting though so I don't think it's going to be expected

@eellison
Copy link
Contributor

eellison commented Jun 6, 2019

Added a test, mypy doesn't allow casting though so I don't think it's going to be expected

I've answered a question before where some one tried to do that, you'd be surpised

suo
suo previously requested changes Jun 7, 2019
const Expr& rhs) {
return Assign(Compound::create(TK_ASSIGN, range, {lhs, rhs}));
}
static Assign create(
Copy link
Member

Choose a reason for hiding this comment

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

This should be Assign(Expr lhs, Expr rhs, Maybe<Expr> type) instead of two different constructors.

Also can you update the big comment at the top of the file with the new form?

@pytorchbot pytorchbot added the module: tests Issues related to tests (not the torch.testing module) label Jun 7, 2019
@driazati driazati dismissed suo’s stale review June 8, 2019 00:17

Addressed comments

@suo suo self-requested a review June 10, 2019 19:54
@yf225
Copy link
Contributor

yf225 commented Jun 11, 2019

@facebook-github-bot
Copy link
Contributor

@driazati merged this pull request in bbcd6cc.

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 is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@kostmo
Copy link
Member

kostmo commented Jun 13, 2019

This change appears to have broken pytorch_linux_trusty_py3_5_test:

Jun 13 18:23:32 ======================================================================
Jun 13 18:23:32 ERROR: test_type_annotate_py3 (__main__.TestScript)
Jun 13 18:23:32 ----------------------------------------------------------------------
Jun 13 18:23:32 Traceback (most recent call last):
Jun 13 18:23:32   File "test_jit.py", line 3238, in test_type_annotate_py3
Jun 13 18:23:32     fn = get_fn('test_type_annotate_py3', script_path)
Jun 13 18:23:32   File "test_jit.py", line 182, in get_fn
Jun 13 18:23:32     spec.loader.exec_module(module)
Jun 13 18:23:32   File "<frozen importlib._bootstrap_external>", line 693, in exec_module
Jun 13 18:23:32   File "<frozen importlib._bootstrap_external>", line 799, in get_code
Jun 13 18:23:32   File "<frozen importlib._bootstrap_external>", line 759, in source_to_code
Jun 13 18:23:32   File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
Jun 13 18:23:32   File "/tmp/tmpxqv9gh0b/script.py", line 4
Jun 13 18:23:32     a : List[int] = []
Jun 13 18:23:32       ^
Jun 13 18:23:32 SyntaxError: invalid syntax

CC @yf225

@facebook-github-bot facebook-github-bot deleted the driazati/type_annot branch July 13, 2020 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: pybind Related to our Python bindings / interactions with other Python libraries module: tests Issues related to tests (not the torch.testing module) oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants