Skip to content

bpo-38307:completes the Stack implementation to yield ending line for each class. #16466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lib/pyclbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
name -- name of the object;
file -- file in which the object is defined;
lineno -- line in the file where the object's definition starts;
end_lineno -- line in the file where the object's definition ends;
parent -- parent of this object, if any;
children -- nested objects contained in this object.
The 'children' attribute is a dictionary mapping names to objects.
Expand Down Expand Up @@ -202,11 +203,13 @@ def _create_tree(fullmodule, path, fname, source, tree, inpackage):
lineno, thisindent = start
# Close previous nested classes and defs.
while stack and stack[-1][1] >= thisindent:
stack[-1][0].end_lineno = start[0] - 1
del stack[-1]
elif token == 'def':
lineno, thisindent = start
# Close previous nested classes and defs.
while stack and stack[-1][1] >= thisindent:
stack[-1][0].end_lineno = start[0] - 1
del stack[-1]
tokentype, func_name, start = next(g)[0:3]
if tokentype != NAME:
Expand All @@ -224,6 +227,7 @@ def _create_tree(fullmodule, path, fname, source, tree, inpackage):
lineno, thisindent = start
# Close previous nested classes and defs.
while stack and stack[-1][1] >= thisindent:
stack[-1][0].end_lineno = start[0] - 1
del stack[-1]
tokentype, class_name, start = next(g)[0:3]
if tokentype != NAME:
Expand Down
6 changes: 4 additions & 2 deletions Lib/test/test_pyclbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,17 @@ def compare(parent1, children1, parent2, children2):
linkage. We separate comparing string and number attributes
from comparing the children of input children.
"""
print("Children 1 is: {}".format(children1))
print("Children 2 is: {}".format(children2))
self.assertEqual(children1.keys(), children2.keys())
for ob in children1.values():
self.assertIs(ob.parent, parent1)
for ob in children2.values():
self.assertIs(ob.parent, parent2)
for key in children1.keys():
o1, o2 = children1[key], children2[key]
t1 = type(o1), o1.name, o1.file, o1.module, o1.lineno
t2 = type(o2), o2.name, o2.file, o2.module, o2.lineno
t1 = type(o1), o1.name, o1.file, o1.module, o1.lineno, o1.end_lineno
t2 = type(o2), o2.name, o2.file, o2.module, o2.lineno, o2.end_lineno
self.assertEqual(t1, t2)
if type(o1) is mb.Class:
self.assertEqual(o1.methods, o2.methods)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Adds end line no in class' use: generating dependency.
: `end_lineno` is added to denote the scope of a class
along with `lineno` which was already present in the codebase.
Patch by Aviral Srivastava.