Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upbpo-39411: pyclbr rewrite on AST #18103
Conversation
Great job! I left an initial batch of comments |
return | ||
|
||
name = node.targets[0].id | ||
child = copy.deepcopy(self.tree[node.value.id]) |
This comment has been minimized.
This comment has been minimized.
pablogsal
Jan 21, 2020
Member
Hummm.....this can be very inefficient as we would be copying the while tree for this id, no?
This comment has been minimized.
This comment has been minimized.
isidentical
Jan 21, 2020
Author
Contributor
we would only copy a Function
object, which has really small memory footprint. If Function
would have many children it would be inefficient but I think it is uncommon to put more than like 5-6 functions inside of another function.
This comment has been minimized.
This comment has been minimized.
pablogsal
Jan 21, 2020
•
Member
I agree, but although minor I wish we could avoid the copy because we would do this for every function.
This comment has been minimized.
This comment has been minimized.
isidentical
Jan 21, 2020
•
Author
Contributor
Ah, I think I can avoid this by manually reconstructing nodes, not sure if it would be the most efficient solution though.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
isidentical
Jan 21, 2020
Author
Contributor
name = node.targets[0].id
value = self.tree[node.value.id]
parent = self.stack[-1]
child = Function(
value.module, name, value.file, node.lineno, parent, value.is_async
)
child.children = copy.deepcopy(value.children)
parent._addchild(name, child)
parent._addmethod(name, node.lineno)
``` what do you think about this?
return | ||
|
||
for module in node.names: | ||
try: |
This comment has been minimized.
This comment has been minimized.
pablogsal
Jan 21, 2020
Member
I find this code a bit messy, maybe we should wrap or modify _readmodule
to return a specific exception or None
if something goes wrong to avoid this double nesting with retry.
This comment has been minimized.
This comment has been minimized.
isidentical
Jan 21, 2020
Author
Contributor
_readmodule
is used directly by public readmodule
and readmodule_ex
interfaces. I dont think such a change is good because we might be simplify here but we need to add a way to raise that exceptions again in public APIs.
This comment has been minimized.
This comment has been minimized.
pablogsal
Jan 21, 2020
•
Member
_readmodule
is used directly by publicreadmodule
andreadmodule_ex
interfaces. I dont think such a change is good because we might be simplify here but we need to add a way to raise that exceptions again in public APIs.
Let me think about what would be the best here, I still find this double try that is catching the same exception a code smell.
This comment has been minimized.
This comment has been minimized.
terryjreedy
Jan 22, 2020
Member
The double try is messy but is part of the original. I worry more about having the same result as before.
Misc/NEWS.d/next/Library/2020-01-21-16-38-25.bpo-39411.9uHFqT.rst
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
bedevere-bot
commented
Jan 21, 2020
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
This comment has been minimized.
This comment has been minimized.
Thanks for the reviews @pablogsal. (I couldn't commit suggestions through github UI because of some indentaton problem) |
Timing pyclbr is a bit tricky because it caches its results, so one call per process. I use tkinter (.init) as longest module I know of, with lots of methods. New code is about twice as fast with current dev debug interpreter. I highly approve ;-) f:\dev\3x>python -c "import time, pyclbr; start=time.time(); pyclbr.readmodule_ex('tkinter'); print(time.time()-start)" f:\dev\3x>git checkout pr_18103 f:\dev\3x>python -c "import time, pyclbr; start=time.time(); pyclbr.readmodule_ex('tkinter'); print(time.time()-start)" 'Old' time with normal installed 64 bit 3.9.0a2 is .5+ so new time might be at least .2 seconds faster, which is subjectively significant. I need to read the NodeVisitor doc to properly understand the subclass. |
return | ||
|
||
for module in node.names: | ||
try: |
This comment has been minimized.
This comment has been minimized.
terryjreedy
Jan 22, 2020
Member
The double try is messy but is part of the original. I worry more about having the same result as before.
isidentical commentedJan 21, 2020
•
edited by bedevere-bot
https://bugs.python.org/issue39411