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

Commit 3b104f5

Browse files
authored
Merge pull request #111 from juanjux/fix/issue102
Fix starting line number of multi-line nodes with tokens
2 parents 6826132 + 27bdb67 commit 3b104f5

12 files changed

+163
-91
lines changed

fixtures/functiondef_docstring.py.native

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"col_offset": 5,
2727
"end_col_offset": 7,
2828
"end_lineno": 4,
29-
"lineno": 4,
29+
"lineno": 2,
3030
"s": "\n And this is the docstring\n "
3131
}
3232
},

fixtures/functiondef_docstring.py.uast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ Module {
4242
And this is the docstring
4343
"
4444
. . . . . . . . . StartPosition: {
45-
. . . . . . . . . . Offset: 58
46-
. . . . . . . . . . Line: 4
45+
. . . . . . . . . . Offset: 20
46+
. . . . . . . . . . Line: 2
4747
. . . . . . . . . . Col: 5
4848
. . . . . . . . . }
4949
. . . . . . . . . EndPosition: {

fixtures/issue102.py.native

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"status": "ok",
3+
"errors": [],
4+
"ast": {
5+
"PY3AST": {
6+
"ast_type": "Module",
7+
"body": [
8+
{
9+
"ast_type": "Expr",
10+
"col_offset": 1,
11+
"lineno": 7,
12+
"value": {
13+
"ast_type": "Str",
14+
"col_offset": 1,
15+
"end_col_offset": 49,
16+
"end_lineno": 7,
17+
"lineno": 1,
18+
"s": "\n select message.*, user.* from message, user\n where message.author_id = user.user_id and (\n user.user_id = ? or\n user.user_id in (select whom_id from follower\n where who_id = ?))\n order by message.pub_date desc limit ?"
19+
}
20+
}
21+
]
22+
}
23+
}
24+
}

fixtures/issue102.py.source

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'''
2+
select message.*, user.* from message, user
3+
where message.author_id = user.user_id and (
4+
user.user_id = ? or
5+
user.user_id in (select whom_id from follower
6+
where who_id = ?))
7+
order by message.pub_date desc limit ?'''

fixtures/issue102.py.uast

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Status: ok
2+
Errors:
3+
UAST:
4+
Module {
5+
. Roles: File
6+
. Children: {
7+
. . 0: Expr {
8+
. . . Roles: Expression
9+
. . . StartPosition: {
10+
. . . . Offset: 254
11+
. . . . Line: 7
12+
. . . . Col: 1
13+
. . . }
14+
. . . Properties: {
15+
. . . . internalRole: body
16+
. . . }
17+
. . . Children: {
18+
. . . . 0: Str {
19+
. . . . . Roles: Literal,String,Expression
20+
. . . . . TOKEN "
21+
select message.*, user.* from message, user
22+
where message.author_id = user.user_id and (
23+
user.user_id = ? or
24+
user.user_id in (select whom_id from follower
25+
where who_id = ?))
26+
order by message.pub_date desc limit ?"
27+
. . . . . StartPosition: {
28+
. . . . . . Offset: 0
29+
. . . . . . Line: 1
30+
. . . . . . Col: 1
31+
. . . . . }
32+
. . . . . EndPosition: {
33+
. . . . . . Offset: 302
34+
. . . . . . Line: 7
35+
. . . . . . Col: 49
36+
. . . . . }
37+
. . . . . Properties: {
38+
. . . . . . internalRole: value
39+
. . . . . }
40+
. . . . }
41+
. . . }
42+
. . }
43+
. }
44+
}
45+

fixtures/issue62_b.py.native

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
"col_offset": 5,
167167
"end_col_offset": 7,
168168
"end_lineno": 14,
169-
"lineno": 14,
169+
"lineno": 12,
170170
"s": "\n Print all SIMPLE_IDENTIFIERs (and counters) from repository\n "
171171
}
172172
},

fixtures/issue62_b.py.uast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ Module {
356356
Print all SIMPLE_IDENTIFIERs (and counters) from repository
357357
"
358358
. . . . . . . . . StartPosition: {
359-
. . . . . . . . . . Offset: 284
360-
. . . . . . . . . . Line: 14
359+
. . . . . . . . . . Offset: 212
360+
. . . . . . . . . . Line: 12
361361
. . . . . . . . . . Col: 5
362362
. . . . . . . . . }
363363
. . . . . . . . . EndPosition: {

fixtures/issue_server101.py.native

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"col_offset": 1,
1515
"end_col_offset": 3,
1616
"end_lineno": 21,
17-
"lineno": 21,
17+
"lineno": 9,
1818
"noops_previous": {
1919
"ast_type": "PreviousNoops",
2020
"col_offset": 1,
@@ -444,7 +444,7 @@
444444
"col_offset": 1,
445445
"end_col_offset": 30,
446446
"end_lineno": 56,
447-
"lineno": 56,
447+
"lineno": 49,
448448
"s": "A cache containing the API documentation for values that we've\nalready seen. This cache is implemented as a dictionary that maps a\nvalue's pyid to its L{ValueDoc}.\n\nNote that if we encounter a value but decide not to introspect it\n(because it's imported from another module), then C{_valuedoc_cache}\nwill contain an entry for the value, but the value will not be listed\nin L{_introspected_values}."
449449
}
450450
},
@@ -495,7 +495,7 @@
495495
"col_offset": 1,
496496
"end_col_offset": 19,
497497
"end_lineno": 60,
498-
"lineno": 60,
498+
"lineno": 59,
499499
"s": "A record which values we've introspected, encoded as a dictionary from\npyid to C{bool}."
500500
}
501501
},
@@ -518,7 +518,7 @@
518518
"col_offset": 5,
519519
"end_col_offset": 7,
520520
"end_lineno": 66,
521-
"lineno": 66,
521+
"lineno": 63,
522522
"noops_previous": {
523523
"ast_type": "PreviousNoops",
524524
"col_offset": 1,
@@ -777,7 +777,7 @@
777777
"col_offset": 5,
778778
"end_col_offset": 7,
779779
"end_lineno": 99,
780-
"lineno": 99,
780+
"lineno": 76,
781781
"s": "\n Generate the API documentation for a specified object by\n introspecting Python values, and return it as a L{ValueDoc}. The\n object to generate documentation for may be specified using\n the C{value} parameter, the C{filename} parameter, I{or} the\n C{name} parameter. (It is an error to specify more than one\n of these three parameters, or to not specify any of them.)\n\n @param value: The python object that should be documented.\n @param filename: The name of the file that contains the python\n source code for a package, module, or script. If\n C{filename} is specified, then C{introspect} will return a\n C{ModuleDoc} describing its contents.\n @param name: The fully-qualified python dotted name of any\n value (including packages, modules, classes, and\n functions). C{DocParser} will automatically figure out\n which module(s) it needs to import in order to find the\n documentation for the specified object.\n @param context: The API documentation for the class of module\n that contains C{value} (if available).\n @param module_name: The name of the module where the value is defined.\n Useful to retrieve the docstring encoding if there is no way to\n detect the module by introspection (such as in properties)\n "
782782
}
783783
},
@@ -2606,7 +2606,7 @@
26062606
"col_offset": 5,
26072607
"end_col_offset": 7,
26082608
"end_lineno": 156,
2609-
"lineno": 156,
2609+
"lineno": 150,
26102610
"s": "\n If a C{ValueDoc} for the given value exists in the valuedoc\n cache, then return it; otherwise, create a new C{ValueDoc},\n add it to the cache, and return it. When possible, the new\n C{ValueDoc}'s C{pyval}, C{repr}, and C{canonical_name}\n attributes will be set appropriately.\n "
26112611
}
26122612
},
@@ -3686,7 +3686,7 @@
36863686
"col_offset": 5,
36873687
"end_col_offset": 7,
36883688
"end_lineno": 194,
3689-
"lineno": 194,
3689+
"lineno": 191,
36903690
"s": "\n Add API documentation information about the module C{module}\n to C{module_doc}.\n "
36913691
}
36923692
},
@@ -7375,7 +7375,7 @@
73757375
"col_offset": 5,
73767376
"end_col_offset": 7,
73777377
"end_lineno": 330,
7378-
"lineno": 330,
7378+
"lineno": 327,
73797379
"s": "\n Add API documentation information about the class C{cls}\n to C{class_doc}.\n "
73807380
}
73817381
},
@@ -9739,7 +9739,7 @@
97399739
"col_offset": 5,
97409740
"end_col_offset": 72,
97419741
"end_lineno": 416,
9742-
"lineno": 416,
9742+
"lineno": 415,
97439743
"s": "Add API documentation information about the function\n C{routine} to C{routine_doc} (specializing it to C{Routine_doc})."
97449744
}
97459745
},
@@ -11772,7 +11772,7 @@
1177211772
"col_offset": 5,
1177311773
"end_col_offset": 66,
1177411774
"end_lineno": 482,
11775-
"lineno": 482,
11775+
"lineno": 481,
1177611776
"s": "Add API documentation information about the property\n C{prop} to C{prop_doc} (specializing it to C{PropertyDoc})."
1177711777
}
1177811778
},
@@ -12432,7 +12432,7 @@
1243212432
"col_offset": 5,
1243312433
"end_col_offset": 7,
1243412434
"end_lineno": 518,
12435-
"lineno": 518,
12435+
"lineno": 510,
1243612436
"s": "\n Return true if the given object is a class. In particular, return\n true if object is an instance of C{types.TypeType} or of\n C{types.ClassType}. This is used instead of C{inspect.isclass()},\n because the latter returns true for objects that are not classes\n (in particular, it returns true for any object that has a\n C{__bases__} attribute, including objects that define\n C{__getattr__} to always return a value).\n "
1243712437
}
1243812438
},
@@ -12640,7 +12640,7 @@
1264012640
"col_offset": 5,
1264112641
"end_col_offset": 20,
1264212642
"end_lineno": 527,
12643-
"lineno": 527,
12643+
"lineno": 525,
1264412644
"s": "Add a type to the lists of types that should be treated as\n classes. By default, this list contains C{TypeType} and\n C{ClassType}."
1264512645
}
1264612646
},
@@ -12778,7 +12778,7 @@
1277812778
"col_offset": 5,
1277912779
"end_col_offset": 7,
1278012780
"end_lineno": 536,
12781-
"lineno": 536,
12781+
"lineno": 533,
1278212782
"s": "\n Return True if C{object} results from a C{from __future__ import feature}\n statement.\n "
1278312783
}
1278412784
},
@@ -13186,7 +13186,7 @@
1318613186
"col_offset": 5,
1318713187
"end_col_offset": 7,
1318813188
"end_lineno": 560,
13189-
"lineno": 560,
13189+
"lineno": 556,
1319013190
"s": "\n Return the docstring for the given value; or C{None} if it\n does not have a docstring.\n @rtype: C{unicode}\n "
1319113191
}
1319213192
},
@@ -14454,7 +14454,7 @@
1445414454
"col_offset": 5,
1445514455
"end_col_offset": 7,
1445614456
"end_lineno": 605,
14457-
"lineno": 605,
14457+
"lineno": 597,
1445814458
"s": "\n @return: the canonical name for C{value}, or C{UNKNOWN} if no\n canonical name can be found. Currently, C{get_canonical_name}\n can find canonical names for: modules; functions; non-nested\n classes; methods of non-nested classes; and some class methods\n of non-nested classes.\n \n @rtype: L{DottedName} or C{UNKNOWN}\n "
1445914459
}
1446014460
},
@@ -16463,7 +16463,7 @@
1646316463
"col_offset": 5,
1646416464
"end_col_offset": 7,
1646516465
"end_lineno": 658,
16466-
"lineno": 658,
16466+
"lineno": 655,
1646716467
"s": "\n Verify the name. E.g., if it's a nested class, then we won't be\n able to find it with the name we constructed.\n "
1646816468
}
1646916469
},
@@ -17288,7 +17288,7 @@
1728817288
"col_offset": 5,
1728917289
"end_col_offset": 7,
1729017290
"end_lineno": 687,
17291-
"lineno": 687,
17291+
"lineno": 683,
1729217292
"s": "\n Return the name of the module containing the given value, or\n C{None} if the module name can't be determined.\n @rtype: L{DottedName}\n "
1729317293
}
1729417294
},
@@ -18008,7 +18008,7 @@
1800818008
"col_offset": 5,
1800918009
"end_col_offset": 7,
1801018010
"end_lineno": 710,
18011-
"lineno": 710,
18011+
"lineno": 705,
1801218012
"s": "\n @return: The module that defines the given function.\n @rtype: C{module}\n @param func: The function whose module should be found.\n @type func: C{function}\n "
1801318013
}
1801418014
},
@@ -18634,7 +18634,7 @@
1863418634
"col_offset": 5,
1863518635
"end_col_offset": 7,
1863618636
"end_lineno": 752,
18637-
"lineno": 752,
18637+
"lineno": 736,
1863818638
"s": "\n Register an introspecter function. Introspecter functions take\n two arguments, a python value and a C{ValueDoc} object, and should\n add information about the given value to the the C{ValueDoc}.\n Usually, the first line of an inspecter function will specialize\n it to a sublass of C{ValueDoc}, using L{ValueDoc.specialize_to()}:\n\n >>> def typical_introspecter(value, value_doc):\n ... value_doc.specialize_to(SomeSubclassOfValueDoc)\n ... <add info to value_doc>\n\n @param priority: The priority of this introspecter, which determines\n the order in which introspecters are tried -- introspecters with lower\n numbers are tried first. The standard introspecters have priorities\n ranging from 20 to 30. The default priority (10) will place new\n introspecters before standard introspecters.\n "
1863918639
}
1864018640
},
@@ -21835,7 +21835,7 @@
2183521835
"col_offset": 5,
2183621836
"end_col_offset": 7,
2183721837
"end_lineno": 859,
21838-
"lineno": 859,
21838+
"lineno": 854,
2183921839
"s": "\n Given a name, return the corresponding value.\n \n @param globs: A namespace to check for the value, if there is no\n module containing the named value. Defaults to __builtin__.\n "
2184021840
}
2184121841
},
@@ -23161,7 +23161,7 @@
2316123161
"col_offset": 5,
2316223162
"end_col_offset": 7,
2316323163
"end_lineno": 897,
23164-
"lineno": 897,
23164+
"lineno": 893,
2316523165
"s": "\n Run the given callable in a 'sandboxed' environment.\n Currently, this includes saving and restoring the contents of\n sys and __builtins__; and suppressing stdin, stdout, and stderr.\n "
2316623166
}
2316723167
},
@@ -24541,7 +24541,7 @@
2454124541
"col_offset": 5,
2454224542
"end_col_offset": 7,
2454324543
"end_lineno": 950,
24544-
"lineno": 950,
24544+
"lineno": 945,
2454524545
"s": "\n Try to determine the line number on which the given item's\n docstring begins. Return the line number, or C{None} if the line\n number can't be determined. The line number of the first line in\n the file is 1.\n "
2454624546
}
2454724547
},
@@ -25319,7 +25319,7 @@
2531925319
"col_offset": 5,
2532025320
"end_col_offset": 7,
2532125321
"end_lineno": 974,
25322-
"lineno": 974,
25322+
"lineno": 969,
2532325323
"noops_previous": {
2532425324
"ast_type": "PreviousNoops",
2532525325
"col_offset": 1,
@@ -26673,7 +26673,7 @@
2667326673
"col_offset": 1,
2667426674
"end_col_offset": 3,
2667526675
"end_lineno": 1056,
26676-
"lineno": 1056,
26676+
"lineno": 1029,
2667726677
"s": "\n######################################################################\n## Zope Extension...\n######################################################################\nclass ZopeIntrospecter(Introspecter):\n VALUEDOC_CLASSES = Introspecter.VALUEDOC_CLASSES.copy()\n VALUEDOC_CLASSES.update({\n 'module': ZopeModuleDoc,\n 'class': ZopeClassDoc,\n 'interface': ZopeInterfaceDoc,\n 'attribute': ZopeAttributeDoc,\n })\n \n def add_module_child(self, child, child_name, module_doc):\n if isinstance(child, zope.interfaces.Interface):\n module_doc.add_zope_interface(child_name)\n else:\n Introspecter.add_module_child(self, child, child_name, module_doc)\n\n def add_class_child(self, child, child_name, class_doc):\n if isinstance(child, zope.interfaces.Interface):\n class_doc.add_zope_interface(child_name)\n else:\n Introspecter.add_class_child(self, child, child_name, class_doc)\n\n def introspect_zope_interface(self, interface, interfacename):\n pass # etc...\n"
2667826678
}
2667926679
}

0 commit comments

Comments
 (0)