8000 bpo-38307: Add end_lineno attribute to pyclbr _Objects by kebab-mai-haddi · Pull Request #24348 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-38307: Add end_lineno attribute to pyclbr _Objects #24348

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

Merged
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1f25ed4
compeltes the Stack implementation to yield ending line for each class.
Sep 28, 2019
7d2354a
reverts whitespace and unwanted changes including functions, comments…
Oct 6, 2019
c8a003d
removes leftover whitespace in b/w functions: unwanted
Oct 6, 2019
7e6f079
Initialize stack of (class, indent) pairs.
Feb 4, 2020
b7c1ce7
removes Stack() custom class and adds direct attribute (end_lineno) i…
Feb 4, 2020
3466f63
corrects the attribute name to end_lineno and sets the same without u…
Feb 8, 2020
f2a58c6
removes unwanted module: inspect
Feb 8, 2020
94edb5b
corrects the way of setting attribute
kebab-mai-haddi Feb 16, 2020
454d305
📜🤖 Added by blurb_it.
blurb-it[bot] Mar 16, 2020
dc0166f
wip: added end_lineno in tests
kebab-mai-haddi Mar 24, 2020
5a26a5c
Merge branch 'endline-in-readmodule-module' of github.com:avisrivasta…
kebab-mai-haddi Mar 24, 2020
ea2090b
wip
kebab-mai-haddi Aug 13, 2020
49d0695
compeltes the Stack implementation to yield ending line for each class.
Sep 28, 2019
33aa14c
reverts whitespace and unwanted changes including functions, comments…
Oct 6, 2019
2f9579a
removes leftover whitespace in b/w functions: unwanted
Oct 6, 2019
668fe22
wip: added end_lineno in tests
kebab-mai-haddi Mar 24, 2020
efb49ea
📜🤖 Added by blurb_it.
blurb-it[bot] Mar 16, 2020
963b783
wip
kebab-mai-haddi Aug 13, 2020
d0d0966
fixed conflicts after diverge
8000 kebab-mai-haddi Jan 27, 2021
d924d4a
adds end_lineno as an attribute for Class and Functions objects
kebab-mai-haddi Jan 27, 2021
78f166f
adds the news.
kebab-mai-haddi Jan 27, 2021
fc74ec7
adds positional arguments in the tests and end_lineno as an argument …
kebab-mai-haddi Jan 27, 2021
b5f29c0
removes debugging print statements.
kebab-mai-haddi Jan 27, 2021
f3c09fe
adds endline no in all the tests for the dummy tree"
kebab-mai-haddi Jan 27, 2021
7337551
adds endline no in all the tests for the dummy tree
kebab-mai-haddi Jan 27, 2021
3e8181c
Merge branch 'endline-in-readmodule-module' of github.com:kebab-mai-h…
kebab-mai-haddi Jan 27, 2021
77784e3
Update 2020-03-16-03-03-21.bpo-38307.2cmw2i.rst
terryjreedy Jan 27, 2021
d73395a
Update 2020-03-16-03-03-21.bpo-38307.2cmw2i.rst
terryjreedy Jan 27, 2021
cc82d4f
Merge remote-tracking branch 'upstream/master' into pr_24348
terryjreedy Feb 1, 2021
9238fcd
Fix end_lineno.
terryjreedy Feb 1, 2021
ed20fa4
Add What's New in 3.10 entry
terryjreedy Feb 1, 2021
48b7341
Update Doc/whatsnew/3.10.rst
terryjreedy Feb 1, 2021
9172efc
Direct calls by by keyword
terryjreedy Feb 1, 2021
d0ca986
blank line
terryjreedy Feb 1, 2021
af31c28
Merge branch 'endline-in-readmodule-module' of https://github.com/keb…
terryjreedy Feb 1, 2021
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
Prev Previous commit
Next Next commit
reverts whitespace and unwanted changes including functions, comments…
… and formatting
  • Loading branch information
Aviral Srivastava committed Oct 6, 2019
commit 7d2354ac2f1a9b83f97d5602b0b910f20d823592
26 changes: 9 additions & 17 deletions Lib/pyclbr.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import importlib.util
import tokenize
from token import NAME, DEDENT, OP
import inspect

__all__ = ["readmodule", "readmodule_ex", "Class", "Function"]

Expand All @@ -51,7 +52,6 @@

class _Object:
"Information about Python class or function."

def __init__(self, module, name, file, lineno, parent):
self.module = module
self.name = name
Expand Down Expand Up @@ -84,13 +84,8 @@ def _addmethod(self, name, lineno):


class Stack(list):

def __init__(self):
import inspect
super().__init__()


def __delitem__(self, key):
import inspect
frames = inspect.stack()
setattr(self[key][0], 'endline',
frames[1].frame.f_locals['start'][0] - 1)
Expand Down Expand Up @@ -182,8 +177,7 @@ def _readmodule(module, path, inpackage=None):
search_path = path + sys.path
spec = importlib.util._find_spec_from_path(fullmodule, search_path)
if spec is None:
raise ModuleNotFoundError(
f"no module named {fullmodule!r}", name=fullmodule)
raise ModuleNotFoundError(f"no module named {fullmodule!r}", name=fullmodule)
_modules[fullmodule] = tree
# Is module a package?
if spec.submodule_search_locations is not None:
Expand Down Expand Up @@ -215,8 +209,7 @@ def _create_tree(fullmodule, path, fname, source, tree, inpackage):
"""
f = io.StringIO(source)

# stack = [] # Initialize stack of (class, indent) pairs.
stack = Stack() # changing the source code so as to get the ending line
stack = Stack() # Initialize stack of (class, indent) pairs.
g = tokenize.generate_tokens(f.readline)
try:
for tokentype, token, start, _end, _line in g:
Expand Down Expand Up @@ -249,14 +242,14 @@ def _create_tree(fullmodule, path, fname, source, tree, inpackage):
del stack[-1]
tokentype, class_name, start = next(g)[0:3]
if tokentype != NAME:
continue # Skip class with syntax error.
continue # Skip class with syntax error.
# Parse what follows the class name.
tokentype, token, start = next(g)[0:3]
inherit = None
if token == '(':
names = [] # Initialize list of superclasses.
names = [] # Initialize list of superclasses.
level = 1
super = [] # Tokens making up current superclass.
super = [] # Tokens making up current superclass.
while True:
tokentype, token, start = next(g)[0:3]
if token in (')', ',') and level == 1:
Expand Down Expand Up @@ -293,7 +286,7 @@ def _create_tree(fullmodule, path, fname, source, tree, inpackage):
if stack:
cur_obj = stack[-1][0]
cur_class = _nest_class(
cur_obj, class_name, lineno, inherit)
cur_obj, class_name, lineno, inherit)
else:
cur_class = Class(fullmodule, class_name, inherit,
fname, lineno)
Expand Down Expand Up @@ -399,7 +392,7 @@ def _main():
else:
path = []
tree = readmodule_ex(mod, path)
def lineno_key(a): return getattr(a, 'lineno', 0)
lineno_key = lambda a: getattr(a, 'lineno', 0)
objs = sorted(tree.values(), key=lineno_key, reverse=True)
indent_level = 2
while objs:
Expand All @@ -422,6 +415,5 @@ def lineno_key(a): return getattr(a, 'lineno', 0)
elif isinstance(obj, Function):
print("{}def {} {}".format(' ' * obj.indent, obj.name, obj.lineno))


if __name__ == "__main__":
_main()
0