Skip to content

[JIT] Disallow plain Tuple type annotation without arg#44585

Closed
SplitInfinity wants to merge 1 commit intogh/splitinfinity/45/basefrom
gh/splitinfinity/45/head
Closed

[JIT] Disallow plain Tuple type annotation without arg#44585
SplitInfinity wants to merge 1 commit intogh/splitinfinity/45/basefrom
gh/splitinfinity/45/head

Conversation

@SplitInfinity
Copy link
Copy Markdown

@SplitInfinity SplitInfinity commented Sep 12, 2020

Stack from ghstack:

Summary
This commit disallows plain Tuple type annotations without any
contained types both in type comments and in-line as Python3-style
type annotations.

Test Plan
This commit adds a unit test for these two situations.

Differential Revision: D23721515

**Summary**
This commit disallows plain `Tuple` type annotations without any
contained types both in type comments and in-line as Python3-style
type annotations.

**Test Plan**
This commit adds a unit test for these two situations.

[ghstack-poisoned]
@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented Sep 12, 2020

💊 CI failures summary and remediations

As of commit 18bafaa (more details on the Dr. CI page):


  • 1/1 failures possibly* introduced in this PR
    • 1/1 non-CircleCI failure(s)

ci.pytorch.org: 1 failed


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 1 time.

@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 12, 2020

Codecov Report

Merging #44585 into gh/splitinfinity/45/base will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@                    Coverage Diff                    @@
##           gh/splitinfinity/45/base   #44585   +/-   ##
=========================================================
  Coverage                     67.98%   67.98%           
=========================================================
  Files                           384      384           
  Lines                         49587    49589    +2     
=========================================================
+ Hits                          33711    33713    +2     
  Misses                        15876    15876           
Impacted Files Coverage Δ
torch/_jit_internal.py 93.46% <100.00%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8dec58d...18bafaa. Read the comment docs.

Copy link
Copy Markdown
Contributor

@eellison eellison left a comment

Choose a reason for hiding this comment

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

Looks good - one question about when we raise vs when we throw.

Do you mind also handling the other case where we generate a bad jit type - here we don't validate the the contained types don't return None before we instantiate Tuple type https://github.com/pytorch/pytorch/blob/master/torch/jit/annotations.py#L286

Comment thread torch/_jit_internal.py


def is_tuple(ann):
if ann is Tuple:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is called in https://github.com/pytorch/pytorch/blob/master/torch/jit/annotations.py#L285 in try_ann_to_type - try_ann_to_type tries to resolve the type if it can, and otherwise returns None. The behavior in the function is getting inconsistent as to whether we throw or return None if it's a bad/unresolvable type. E.g. we're now erroring in https://github.com/pytorch/pytorch/blob/master/torch/jit/annotations.py#L302.

I think we should maybe return None instead of erroring. What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's true that the error msg is better now - in the future we could add a why_not parameter return value to improve but that should probably be its own PR...

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Sorry I deleted my previous comment because I didn't understand what you were saying at first. It is possible to return None instead of erroring here, but it will require more code due to small differences in the typing module between python3.6 and python3.8. You can see a concrete example of doing this in one of my previous diffs for Dict. The red diff is what I would have to add back. Take a look and if that extra code is acceptable, I can do it for Tuple and List too.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@SplitInfinity merged this pull request in ffe127e.

xuzhao9 pushed a commit that referenced this pull request Sep 18, 2020
Summary:
Pull Request resolved: #44585

**Summary**
This commit disallows plain `Tuple` type annotations without any
contained types both in type comments and in-line as Python3-style
type annotations.

**Test Plan**
This commit adds a unit test for these two situations.

Test Plan: Imported from OSS

Reviewed By: gmagogsfm

Differential Revision: D23721515

Pulled By: SplitInfinity

fbshipit-source-id: e11c77a4fac0b81cd535c37a31b9f4129c276592
@facebook-github-bot facebook-github-bot deleted the gh/splitinfinity/45/head branch September 20, 2020 14:17
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Pull Request resolved: pytorch#44585

**Summary**
This commit disallows plain `Tuple` type annotations without any
contained types both in type comments and in-line as Python3-style
type annotations.

**Test Plan**
This commit adds a unit test for these two situations.

Test Plan: Imported from OSS

Reviewed By: gmagogsfm

Differential Revision: D23721515

Pulled By: SplitInfinity

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants