Skip to content

Fix index parsing on Python-3.9#48676

Closed
malfet wants to merge 1 commit intomasterfrom
malfet/fix-ast-parsing-in-3.9
Closed

Fix index parsing on Python-3.9#48676
malfet wants to merge 1 commit intomasterfrom
malfet/fix-ast-parsing-in-3.9

Conversation

@malfet
Copy link
Copy Markdown
Contributor

@malfet malfet commented Dec 1, 2020

In 3.9, ast.Index and ast.ExtSlice are deprecated, so:

  • ast.parse('img[3]', model='eval') evaluates to
    Expression(body=Subscript(value=Name(id='img'), slice=Constant(value=3))) by 3.9,
    but was previously evaluated to Expression(body=Subscript(value=Name(id='img'), slice=Index(value=Num(n=3))))
  • and ast.parse('img[..., 10:20]', mode='eval') is evaluated to
    Subscript(value=Name(id='img'),slice=Tuple(elts=[Constant(value=Ellipsis),Slice(lower=Constant(value=10), upper=Constant(value=20))]))
    , but was evaluated to
    Subscript(value=Name(id='img'), slice=ExtSlice(dims=[Index(value=Ellipsis()), Slice(lower=Num(n=10), upper=Num(n=20), step=None)]))

Fixes #48674

@malfet malfet requested a review from zou3519 December 1, 2020 23:47
@facebook-github-bot facebook-github-bot added cla signed oncall: jit Add this issue/PR to JIT oncall triage queue labels Dec 1, 2020
@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented Dec 2, 2020

💊 CI failures summary and remediations

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


None of the CI failures appear to be your fault 💚



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 9 times.

@malfet malfet force-pushed the malfet/fix-ast-parsing-in-3.9 branch from e099cbe to d136cda Compare December 2, 2020 01:53
@malfet malfet requested review from a team and gmagogsfm December 2, 2020 01:54
Copy link
Copy Markdown
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.

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

@malfet malfet added this to the 1.7.1 milestone Dec 2, 2020
@malfet malfet force-pushed the malfet/fix-ast-parsing-in-3.9 branch from d136cda to 9508640 Compare December 2, 2020 02:05
Copy link
Copy Markdown
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.

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

Copy link
Copy Markdown
Contributor

@walterddr walterddr left a comment

Choose a reason for hiding this comment

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

lgtm

Comment thread torch/jit/frontend.py
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@malfet merged this pull request in 071344d.

malfet added a commit that referenced this pull request Dec 2, 2020
Summary:
In 3.9, `ast.Index` and `ast.ExtSlice` are deprecated, so:
-  `ast.parse('img[3]', model='eval')` evaluates to
`Expression(body=Subscript(value=Name(id='img'), slice=Constant(value=3)))` by 3.9,
but was previously evaluated to `Expression(body=Subscript(value=Name(id='img'), slice=Index(value=Num(n=3))))`
- and `ast.parse('img[..., 10:20]', mode='eval')` is evaluated to
`
Subscript(value=Name(id='img'),slice=Tuple(elts=[Constant(value=Ellipsis),Slice(lower=Constant(value=10), upper=Constant(value=20))]))
`
, but was evaluated to
`
Subscript(value=Name(id='img'), slice=ExtSlice(dims=[Index(value=Ellipsis()), Slice(lower=Num(n=10), upper=Num(n=20), step=None)]))
`

Fixes #48674

Pull Request resolved: #48676

Reviewed By: seemethere, gmagogsfm

Differential Revision: D25261323

Pulled By: malfet

fbshipit-source-id: cc818ecc596a062ed5f1a1d11d3fdf0f22bf7f4a
seemethere pushed a commit that referenced this pull request Dec 2, 2020
Summary:
In 3.9, `ast.Index` and `ast.ExtSlice` are deprecated, so:
-  `ast.parse('img[3]', model='eval')` evaluates to
`Expression(body=Subscript(value=Name(id='img'), slice=Constant(value=3)))` by 3.9,
but was previously evaluated to `Expression(body=Subscript(value=Name(id='img'), slice=Index(value=Num(n=3))))`
- and `ast.parse('img[..., 10:20]', mode='eval')` is evaluated to
`
Subscript(value=Name(id='img'),slice=Tuple(elts=[Constant(value=Ellipsis),Slice(lower=Constant(value=10), upper=Constant(value=20))]))
`
, but was evaluated to
`
Subscript(value=Name(id='img'), slice=ExtSlice(dims=[Index(value=Ellipsis()), Slice(lower=Num(n=10), upper=Num(n=20), step=None)]))
`

Fixes #48674

Pull Request resolved: #48676

Reviewed By: seemethere, gmagogsfm

Differential Revision: D25261323

Pulled By: malfet

fbshipit-source-id: cc818ecc596a062ed5f1a1d11d3fdf0f22bf7f4a
shaibagon pushed a commit to shaibagon/pytorch that referenced this pull request Dec 3, 2020
Summary:
In 3.9, `ast.Index` and `ast.ExtSlice` are deprecated, so:
-  `ast.parse('img[3]', model='eval')` evaluates to
`Expression(body=Subscript(value=Name(id='img'), slice=Constant(value=3)))` by 3.9,
but was previously evaluated to `Expression(body=Subscript(value=Name(id='img'), slice=Index(value=Num(n=3))))`
- and `ast.parse('img[..., 10:20]', mode='eval')` is evaluated to
`
Subscript(value=Name(id='img'),slice=Tuple(elts=[Constant(value=Ellipsis),Slice(lower=Constant(value=10), upper=Constant(value=20))]))
`
, but was evaluated to
`
Subscript(value=Name(id='img'), slice=ExtSlice(dims=[Index(value=Ellipsis()), Slice(lower=Num(n=10), upper=Num(n=20), step=None)]))
`

Fixes pytorch#48674

Pull Request resolved: pytorch#48676

Reviewed By: seemethere, gmagogsfm

Differential Revision: D25261323

Pulled By: malfet

fbshipit-source-id: cc818ecc596a062ed5f1a1d11d3fdf0f22bf7f4a
@malfet malfet deleted the malfet/fix-ast-parsing-in-3.9 branch December 3, 2020 18:33
malfet added a commit that referenced this pull request Jan 27, 2021
Mostly replace `global Foo` with `make_global(Foo)`
The only real fix is generating Subscript annotation, which is a follow up from #48676
malfet added a commit that referenced this pull request Jan 27, 2021
Mostly replace `global Foo` with `make_global(Foo)`
The only real fix is generating Subscript annotation, which is a follow up from #48676
facebook-github-bot pushed a commit that referenced this pull request Jan 27, 2021
Summary:
Mostly replace `global Foo` with `make_global(Foo)`
The only real fix is generating Subscript annotation, which is a follow up from #48676

Fixes #49617

Pull Request resolved: #51182

Reviewed By: gmagogsfm

Differential Revision: D26095244

Pulled By: malfet

fbshipit-source-id: 0e043d9a2cf43fff71dfbb341f708cd7af87c39a
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
In 3.9, `ast.Index` and `ast.ExtSlice` are deprecated, so:
-  `ast.parse('img[3]', model='eval')` evaluates to
`Expression(body=Subscript(value=Name(id='img'), slice=Constant(value=3)))` by 3.9,
but was previously evaluated to `Expression(body=Subscript(value=Name(id='img'), slice=Index(value=Num(n=3))))`
- and `ast.parse('img[..., 10:20]', mode='eval')` is evaluated to
`
Subscript(value=Name(id='img'),slice=Tuple(elts=[Constant(value=Ellipsis),Slice(lower=Constant(value=10), upper=Constant(value=20))]))
`
, but was evaluated to
`
Subscript(value=Name(id='img'), slice=ExtSlice(dims=[Index(value=Ellipsis()), Slice(lower=Num(n=10), upper=Num(n=20), step=None)]))
`

Fixes pytorch#48674

Pull Request resolved: pytorch#48676

Reviewed By: seemethere, gmagogsfm

Differential Revision: D25261323

Pulled By: malfet

fbshipit-source-id: cc818ecc596a062ed5f1a1d11d3fdf0f22bf7f4a
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Mostly replace `global Foo` with `make_global(Foo)`
The only real fix is generating Subscript annotation, which is a follow up from pytorch#48676

Fixes pytorch#49617

Pull Request resolved: pytorch#51182

Reviewed By: gmagogsfm

Differential Revision: D26095244

Pulled By: malfet

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

Labels

cla signed Merged oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

torch.jit.script is often broken in Python-3.9

5 participants