Skip to content
This repository was archived by the owner on Mar 8, 2020. It is now read-only.

Commit 5dd1d80

Browse files
authored
Merge pull request #149 from juanjux/fix/comments
Comment improvements
2 parents 33cfcca + d026de4 commit 5dd1d80

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1005
-5359
lines changed

Diff for: driver/normalizer/annotation.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,17 @@ var AnnotationRules = On(Any).Self(
198198
On(pyast.Name).Roles(uast.Identifier, uast.Expression),
199199
// Comments and non significative whitespace
200200
On(pyast.SameLineNoops).Roles(uast.Comment),
201-
On(pyast.PreviousNoops).Roles(uast.Whitespace).Children(
202-
On(HasInternalRole("lines")).Roles(uast.Comment),
201+
On(pyast.PreviousNoops).Roles(uast.Noop).Children(
202+
On(HasInternalRole("lines")).Self(
203+
On(HasProperty("noop_line", "\n")).Roles(uast.Noop, uast.Whitespace),
204+
On(Not(HasProperty("noop_line", "\n"))).Roles(uast.Noop, uast.Comment),
205+
),
203206
),
204-
On(pyast.RemainderNoops).Roles(uast.Whitespace).Children(
205-
On(HasInternalRole("lines")).Roles(uast.Comment),
207+
On(pyast.RemainderNoops).Roles(uast.Noop).Children(
208+
On(HasInternalRole("lines")).Self(
209+
On(HasProperty("noop_line", "\n")).Roles(uast.Noop, uast.Whitespace),
210+
On(Not(HasProperty("noop_line", "\n"))).Roles(uast.Noop, uast.Comment),
211+
),
206212
),
207213

208214
// TODO: check what Constant nodes are generated in the python AST and improve this

Diff for: fixtures/annotations.py.uast

-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ Module {
8282
. . . Properties: {
8383
. . . . internalRole: body
8484
. . . . simple: 1
85-
. . . . value: <nil>
8685
. . . }
8786
. . . Children: {
8887
. . . . 0: Name {
@@ -144,8 +143,6 @@ Module {
144143
. . . . . Roles: Function,Declaration,Incomplete,Argument
145144
. . . . . Properties: {
146145
. . . . . . internalRole: args
147-
. . . . . . kwarg: <nil>
148-
. . . . . . vararg: <nil>
149146
. . . . . }
150147
. . . . . Children: {
151148
. . . . . . 0: arg {

Diff for: fixtures/aritmeticops.py.native

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
"ast_type": "NoopLine",
222222
"col_offset": 1,
223223
"lineno": 8,
224-
"noop_line": "# 1@2 FIXME: matmul\n"
224+
"noop_line": " 1@2 FIXME: matmul\n"
225225
}
226226
]
227227
}

Diff for: fixtures/aritmeticops.py.uast

+3-3
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ Module {
475475
. . . }
476476
. . }
477477
. . 7: RemainderNoops {
478-
. . . Roles: Whitespace
478+
. . . Roles: Noop
479479
. . . StartPosition: {
480480
. . . . Offset: 30
481481
. . . . Line: 8
@@ -491,8 +491,8 @@ Module {
491491
. . . }
492492
. . . Children: {
493493
. . . . 0: NoopLine {
494-
. . . . . Roles: Comment
495-
. . . . . TOKEN "# 1@2 FIXME: matmul
494+
. . . . . Roles: Noop,Comment
495+
. . . . . TOKEN " 1@2 FIXME: matmul
496496
"
497497
. . . . . StartPosition: {
498498
. . . . . . Offset: 30

Diff for: fixtures/assert_constant.py.uast

-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Module {
2020
. . . }
2121
. . . Properties: {
2222
. . . . internalRole: body
23-
. . . . msg: <nil>
2423
. . . }
2524
. . . Children: {
2625
. . . . 0: BoolLiteral {
@@ -58,7 +57,6 @@ Module {
5857
. . . }
5958
. . . Properties: {
6059
. . . . internalRole: body
61-
. . . . msg: <nil>
6260
. . . }
6361
. . . Children: {
6462
. . . . 0: BoolLiteral {

Diff for: fixtures/classdef.py.native

+4-32
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,7 @@
115115
"end_col_offset": 1,
116116
"end_lineno": 5,
117117
"lineno": 5,
118-
"lines": [
119-
{
120-
"ast_type": "NoopLine",
121-
"col_offset": 1,
122-
"lineno": 5,
123-
"noop_line": "\n"
124-
}
125-
]
118+
"lines": []
126119
}
127120
},
128121
{
@@ -200,14 +193,7 @@
200193
"end_col_offset": 1,
201194
"end_lineno": 8,
202195
"lineno": 8,
203-
"lines": [
204-
{
205-
"ast_type": "NoopLine",
206-
"col_offset": 1,
207-
"lineno": 8,
208-
"noop_line": "\n"
209-
}
210-
]
196+
"lines": []
211197
}
212198
}
213199
}
@@ -246,14 +232,7 @@
246232
"end_col_offset": 1,
247233
"end_lineno": 12,
248234
"lineno": 12,
249-
"lines": [
250-
{
251-
"ast_type": "NoopLine",
252-
"col_offset": 1,
253-
"lineno": 12,
254-
"noop_line": "\n"
255-
}
256-
]
235+
"lines": []
257236
}
258237
}
259238
],
@@ -354,14 +333,7 @@
354333
"end_col_offset": 1,
355334
"end_lineno": 16,
356335
"lineno": 16,
357-
"lines": [
358-
{
359-
"ast_type": "NoopLine",
360-
"col_offset": 1,
361-
"lineno": 16,
362-
"noop_line": "\n"
363-
}
364-
]
336+
"lines": []
365337
}
366338
}
367339
],

Diff for: fixtures/classdef.py.uast

+4-88
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,11 @@ Module {
4141
. . . . . . . . Line: 2
4242
. . . . . . . . Col: 16
4343
. . . . . . . }
44-
. . . . . . . Properties: {
45-
. . . . . . . . returns: <nil>
46-
. . . . . . . }
4744
. . . . . . . Children: {
4845
. . . . . . . . 0: arguments {
4946
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument
5047
. . . . . . . . . Properties: {
5148
. . . . . . . . . . internalRole: args
52-
. . . . . . . . . . kwarg: <nil>
53-
. . . . . . . . . . vararg: <nil>
5449
. . . . . . . . . }
5550
. . . . . . . . . Children: {
5651
. . . . . . . . . . 0: arg {
@@ -67,7 +62,6 @@ Module {
6762
. . . . . . . . . . . . Col: 21
6863
. . . . . . . . . . . }
6964
. . . . . . . . . . . Properties: {
70-
. . . . . . . . . . . . annotation: <nil>
7165
. . . . . . . . . . . . internalRole: args
7266
. . . . . . . . . . . }
7367
. . . . . . . . . . }
@@ -206,16 +200,11 @@ Module {
206200
. . . . . . . . Line: 6
207201
. . . . . . . . Col: 14
208202
. . . . . . . }
209-
. . . . . . . Properties: {
210-
. . . . . . . . returns: <nil>
211-
. . . . . . . }
212203
. . . . . . . Children: {
213204
. . . . . . . . 0: arguments {
214205
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument
215206
. . . . . . . . . Properties: {
216207
. . . . . . . . . . internalRole: args
217-
. . . . . . . . . . kwarg: <nil>
218-
. . . . . . . . . . vararg: <nil>
219208
. . . . . . . . . }
220209
. . . . . . . . . Children: {
221210
. . . . . . . . . . 0: arg {
@@ -232,12 +221,11 @@ Module {
232221
. . . . . . . . . . . . Col: 19
233222
. . . . . . . . . . . }
234223
. . . . . . . . . . . Properties: {
235-
. . . . . . . . . . . . annotation: <nil>
236224
. . . . . . . . . . . . internalRole: args
237225
. . . . . . . . . . . }
238226
. . . . . . . . . . . Children: {
239227
. . . . . . . . . . . . 0: PreviousNoops {
240-
. . . . . . . . . . . . . Roles: Whitespace
228+
. . . . . . . . . . . . . Roles: Noop
241229
. . . . . . . . . . . . . StartPosition: {
242230
. . . . . . . . . . . . . . Offset: 72
243231
. . . . . . . . . . . . . . Line: 5
@@ -251,21 +239,6 @@ Module {
251239
. . . . . . . . . . . . . Properties: {
252240
. . . . . . . . . . . . . . internalRole: noops_previous
253241
. . . . . . . . . . . . . }
254-
. . . . . . . . . . . . . Children: {
255-
. . . . . . . . . . . . . . 0: NoopLine {
256-
. . . . . . . . . . . . . . . Roles: Comment
257-
. . . . . . . . . . . . . . . TOKEN "
258-
"
259-
. . . . . . . . . . . . . . . StartPosition: {
260-
. . . . . . . . . . . . . . . . Offset: 72
261-
. . . . . . . . . . . . . . . . Line: 5
262-
. . . . . . . . . . . . . . . . Col: 1
263-
. . . . . . . . . . . . . . . }
264-
. . . . . . . . . . . . . . . Properties: {
265-
. . . . . . . . . . . . . . . . internalRole: lines
266-
. . . . . . . . . . . . . . . }
267-
. . . . . . . . . . . . . . }
268-
. . . . . . . . . . . . . }
269242
. . . . . . . . . . . . }
270243
. . . . . . . . . . . }
271244
. . . . . . . . . . }
@@ -283,7 +256,6 @@ Module {
283256
. . . . . . . . . . . . Col: 25
284257
. . . . . . . . . . . }
285258
. . . . . . . . . . . Properties: {
286-
. . . . . . . . . . . . annotation: <nil>
287259
. . . . . . . . . . . . internalRole: args
288260
. . . . . . . . . . . }
289261
. . . . . . . . . . }
@@ -321,16 +293,11 @@ Module {
321293
. . . . . . . . Line: 9
322294
. . . . . . . . Col: 5
323295
. . . . . . . }
324-
. . . . . . . Properties: {
325-
. . . . . . . . returns: <nil>
326-
. . . . . . . }
327296
. . . . . . . Children: {
328297
. . . . . . . . 0: arguments {
329298
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument
330299
. . . . . . . . . Properties: {
331300
. . . . . . . . . . internalRole: args
332-
. . . . . . . . . . kwarg: <nil>
333-
. . . . . . . . . . vararg: <nil>
334301
. . . . . . . . . }
335302
. . . . . . . . }
336303
. . . . . . . . 1: FunctionDef.body {
@@ -390,7 +357,7 @@ Module {
390357
. . . . . . . . . . . . . . . }
391358
. . . . . . . . . . . . . . . Children: {
392359
. . . . . . . . . . . . . . . . 0: PreviousNoops {
393-
. . . . . . . . . . . . . . . . . Roles: Whitespace
360+
. . . . . . . . . . . . . . . . . Roles: Noop
394361
. . . . . . . . . . . . . . . . . StartPosition: {
395362
. . . . . . . . . . . . . . . . . . Offset: 114
396363
. . . . . . . . . . . . . . . . . . Line: 8
@@ -404,21 +371,6 @@ Module {
404371
. . . . . . . . . . . . . . . . . Properties: {
405372
. . . . . . . . . . . . . . . . . . internalRole: noops_previous
406373
. . . . . . . . . . . . . . . . . }
407-
. . . . . . . . . . . . . . . . . Children: {
408-
. . . . . . . . . . . . . . . . . . 0: NoopLine {
409-
. . . . . . . . . . . . . . . . . . . Roles: Comment
410-
. . . . . . . . . . . . . . . . . . . TOKEN "
411-
"
412-
. . . . . . . . . . . . . . . . . . . StartPosition: {
413-
. . . . . . . . . . . . . . . . . . . . Offset: 114
414-
. . . . . . . . . . . . . . . . . . . . Line: 8
415-
. . . . . . . . . . . . . . . . . . . . Col: 1
416-
. . . . . . . . . . . . . . . . . . . }
417-
. . . . . . . . . . . . . . . . . . . Properties: {
418-
. . . . . . . . . . . . . . . . . . . . internalRole: lines
419-
. . . . . . . . . . . . . . . . . . . }
420-
. . . . . . . . . . . . . . . . . . }
421-
. . . . . . . . . . . . . . . . . }
422374
. . . . . . . . . . . . . . . . }
423375
. . . . . . . . . . . . . . . }
424376
. . . . . . . . . . . . . . }
@@ -463,16 +415,11 @@ Module {
463415
. . . . . . . . Line: 13
464416
. . . . . . . . Col: 5
465417
. . . . . . . }
466-
. . . . . . . Properties: {
467-
. . . . . . . . returns: <nil>
468-
. . . . . . . }
469418
. . . . . . . Children: {
470419
. . . . . . . . 0: arguments {
471420
. . . . . . . . . Roles: Function,Declaration,Incomplete,Argument
472421
. . . . . . . . . Properties: {
473422
. . . . . . . . . . internalRole: args
474-
. . . . . . . . . . kwarg: <nil>
475-
. . . . . . . . . . vararg: <nil>
476423
. . . . . . . . . }
477424
. . . . . . . . . Children: {
478425
. . . . . . . . . . 0: arg {
@@ -489,12 +436,11 @@ Module {
489436
. . . . . . . . . . . . Col: 14
490437
. . . . . . . . . . . }
491438
. . . . . . . . . . . Properties: {
492-
. . . . . . . . . . . . annotation: <nil>
493439
. . . . . . . . . . . . internalRole: args
494440
. . . . . . . . . . . }
495441
. . . . . . . . . . . Children: {
496442
. . . . . . . . . . . . 0: PreviousNoops {
497-
. . . . . . . . . . . . . Roles: Whitespace
443+
. . . . . . . . . . . . . Roles: Noop
498444
. . . . . . . . . . . . . StartPosition: {
499445
. . . . . . . . . . . . . . Offset: 165
500446
. . . . . . . . . . . . . . Line: 12
@@ -508,21 +454,6 @@ Module {
508454
. . . . . . . . . . . . . Properties: {
509455
. . . . . . . . . . . . . . internalRole: noops_previous
510456
. . . . . . . . . . . . . }
511-
. . . . . . . . . . . . . Children: {
512-
. . . . . . . . . . . . . . 0: NoopLine {
513-
. . . . . . . . . . . . . . . Roles: Comment
514-
. . . . . . . . . . . . . . . TOKEN "
515-
"
516-
. . . . . . . . . . . . . . . StartPosition: {
517-
. . . . . . . . . . . . . . . . Offset: 165
518-
. . . . . . . . . . . . . . . . Line: 12
519-
. . . . . . . . . . . . . . . . Col: 1
520-
. . . . . . . . . . . . . . . }
521-
. . . . . . . . . . . . . . . Properties: {
522-
. . . . . . . . . . . . . . . . internalRole: lines
523-
. . . . . . . . . . . . . . . }
524-
. . . . . . . . . . . . . . }
525-
. . . . . . . . . . . . . }
526457
. . . . . . . . . . . . }
527458
. . . . . . . . . . . }
528459
. . . . . . . . . . }
@@ -683,7 +614,7 @@ Module {
683614
. . . . . }
684615
. . . . . Children: {
685616
. . . . . . 0: PreviousNoops {
686-
. . . . . . . Roles: Whitespace
617+
. . . . . . . Roles: Noop
687618
. . . . . . . StartPosition: {
688619
. . . . . . . . Offset: 220
689620
. . . . . . . . Line: 16
@@ -697,21 +628,6 @@ Module {
697628
. . . . . . . Properties: {
698629
. . . . . . . . internalRole: noops_previous
699630
. . . . . . . }
700-
. . . . . . . Children: {
701-
. . . . . . . . 0: NoopLine {
702-
. . . . . . . . . Roles: Comment
703-
. . . . . . . . . TOKEN "
704-
"
705-
. . . . . . . . . StartPosition: {
706-
. . . . . . . . . . Offset: 220
707-
. . . . . . . . . . Line: 16
708-
. . . . . . . . . . Col: 1
709-
. . . . . . . . . }
710-
. . . . . . . . . Properties: {
711-
. . . . . . . . . . internalRole: lines
712-
. . . . . . . . . }
713-
. . . . . . . . }
714-
. . . . . . . }
715631
. . . . . . }
716632
. . . . . }
717633
. . . . }

Diff for: fixtures/classdef_inheritance.py.native

+2-16
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,7 @@
5353
"end_col_offset": 1,
5454
"end_lineno": 3,
5555
"lineno": 3,
56-
"lines": [
57-
{
58-
"ast_type": "NoopLine",
59-
"col_offset": 1,
60-
"lineno": 3,
61-
"noop_line": "\n"
62-
}
63-
]
56+
"lines": []
6457
}
6558
},
6659
{
@@ -97,14 +90,7 @@
9790
"end_col_offset": 1,
9891
"end_lineno": 6,
9992
"lineno": 6,
100-
"lines": [
101-
{
102-
"ast_type": "NoopLine",
103-
"col_offset": 1,
104-
"lineno": 6,
105-
"noop_line": "\n"
106-
}
107-
]
93+
"lines": []
10894
}
10995
}
11096
}

0 commit comments

Comments
 (0)