Skip to content

Commit 2ff24e7

Browse files
author
Randall C. O'Reilly
committed
prevent out-of-range err in TypeSpec
1 parent 1ccfc36 commit 2ff24e7

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pyprint/nodes.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,14 +1712,16 @@ func (p *printer) spec(spec ast.Spec, n int, doIndent bool) {
17121712
if s.Assign.IsValid() {
17131713
p.print(token.ASSIGN, blank)
17141714
}
1715-
doc := p.comments[p.cindex-1]
1716-
p.pyFuncComments(doc) // neither s.Doc nor s.Comment work here
1717-
p.expr(s.Type)
1718-
p.print(newline)
1719-
p.print("<<<<EndClass: ")
1720-
p.expr(s.Name)
1721-
p.print(">>>>", newline)
1722-
// p.setComment(s.Comment)
1715+
if p.cindex-1 < len(p.comments) {
1716+
doc := p.comments[p.cindex-1]
1717+
p.pyFuncComments(doc) // neither s.Doc nor s.Comment work here
1718+
p.expr(s.Type)
1719+
p.print(newline)
1720+
p.print("<<<<EndClass: ")
1721+
p.expr(s.Name)
1722+
p.print(">>>>", newline)
1723+
// p.setComment(s.Comment)
1724+
}
17231725

17241726
default:
17251727
panic("unreachable")

0 commit comments

Comments
 (0)