bpo-6691: Support for nested classes and functions in pyclbr#2503
Conversation
terryjreedy
left a comment
There was a problem hiding this comment.
After the patch, the biggest flaw of the module, in my opinion, will be that is discards the line order of statements. If a collections.OrderedDict is forward compatible with dicts, I would like to make the replacement. I want to ask Raymond H about this.
Cheryl, there are a couple of questions about the isinstance checks that might be related to the test failure and fix you mentioned.
Sorry, something went wrong.
|
Some of the changes I suggested are outside the scope of this issue and should be left for another. Using DefaultDict is one issue. Removing print calls from tests is another. I think splitting the private function into two to simplify the test of the new feature can be included, but as a separate commit. |
Sorry, something went wrong.
|
I made a separate commit for splitting _readmodule into two functions. It's only 5 lines, including whitespace and docstring. It didn't pass the tests at first and I've been debugging it for hours. It ended up that the calls back to Thanks! |
Sorry, something went wrong.
|
I believe _Object should be private, if not removed. I asked on core-mentorship about the current added/changed notes as well as what is allowed in the doc if Object is removed. |
Sorry, something went wrong.
|
In a previous version of this comment, I said It is still true that there is no test of readmodule, and that one might be added in a new test revision issue. With a test, the implementation could be reduced to a dict comprehension. |
Sorry, something went wrong.
|
Find in Files says neither _getname nor _getnamelist appear in test_pyclbr. Adding some would be another issue. Without knowing in detail what tokenizer emits, I am not sure they will handle legal multiline imports like |
Sorry, something went wrong.
|
I assumed that any missing parameters would immediately result in NameErrors. If the test failed because of a missing parameter, and did not raise NameError, I would be surprised and puzzled. Looking at the test, one problem I see is that test_others() does multiple cm tests in sequence, so first to fail stops testing of the rest. If different files exercise different pathways with different needed parameters, it would take several runs to get them all. I am sorry that this was much more troublesome that I expected. This function should be revised to use subtests (self.subTest) so all run regardless of failure. This is at least the fourth thing to fix in this file. Prints, temporary file, and missing tests are another. |
Sorry, something went wrong.
|
After review, I think the only thing left for this issue is to make Object private. If I get no response on core mentorship, I will copy the current redundant doc format, but put Function first and note on Class that it has 2 more. The doc should also mention that Class.methods is redundant with Class.children in that the former lists the Functions in the latter. It is only kept for back-compatibility. |
Sorry, something went wrong.
This wasn't a problem at all. Every chance I get to debug and track something down is more learning for me, so it's all good. I apologize if it sounded like I was complaining. I just brought it up because I was surprised I didn't get a warning while running the tests and to find if there were any tricks (or tools) that would have helped me reach the endpoint sooner. |
Sorry, something went wrong.
terryjreedy
left a comment
There was a problem hiding this comment.
I changed my mind about the new test. It is so opaque that I trust it less than the code. The function that creates code I cannot see from a tuple structure and the the custom equality function that compares the nested output to nodes created from the tuple structure need tests themselves ;-).
Transparent would be a chunk of code that is fed to readmodule_ex and a constructed dict that is obviously correct for the code, which is compared to the output of readmodule_ex. Python already has tested dict equality comparison.
The tricky part of the construction is the double linkage, which is completed with _add_child. This new method should be tested (easy).
Sorry, something went wrong.
|
Thanks for making all those changes. I know you said it needs more, but it looks awesome! |
Sorry, something went wrong.
|
I think I did what I said was essential. Anyway, there were two conceptual improvements.
Added now: I believe the helpers should not just call .add_child, but should be incorporated into it, and the Class override.
Side node: general tree equality is hard because it is not initially known which child to pair with which. Here, the children for each node are uniquely labelled and the labels must match. Added now. This is still clumsy. A possible solution: rename _Object as _Node. Replace None as the mod-level parent with top, an instance of _Node. Prime the _create_tree pump by initializing stack with [(top, -1)]. Since top is never popped, stack is never empty and we dump the stack test. Add all Function and Class node with (stack[-1][0]).add_child. The creation of 'expected' in the test start with top = _Node(...) and all the addition would be with something.add_child. The compare function would have two parameters, node1 and node2, and would be .eq of _Node (where it could be tested). _Node would then need one more method, .export_children. It would change the parent of all the children to None and then return the dict to be returned to users. Just where to do this would be a detail to be worked out after checking the tests. I am not going to do this, unless revision is needed for IDLE. I would rather work on applying the lesson of matching code to concepts to IDLE. |
Sorry, something went wrong.
* Revert "bpo-30854: Fix compile error when --without-threads (#2581)" This reverts commit 0c31163. * Revert "NEWS for 30777 (#2576)" This reverts commit aaa917f. * Revert "bpo-21624: IDLE -- minor htest fixes (#2575)" This reverts commit 2000150. * Revert "bpo-30777: IDLE: configdialog - add docstrings and improve comments (#2440)" This reverts commit 7eb5883. * Revert "bpo-30319: socket.close() now ignores ECONNRESET (#2565)" This reverts commit 67e1478. * Revert "bpo-30789: Use a single memory block for co_extra. (#2555)" This reverts commit 378ebb6. * Revert "bpo-30845: Enhance test_concurrent_futures cleanup (#2564)" This reverts commit 3df9dec. * Revert "bpo-29293: multiprocessing.Condition.notify() lacks parameter `n` (#2480)" This reverts commit 4835041. * Revert "Remove outdated FOX from GUI FAQ (GH-2538)" This reverts commit d3ed287. * Revert "bpo-6691: Pyclbr now reports nested classes and functions. (#2503)" This reverts commit 246ff3b. * Revert "bpo-29464: Rename METH_FASTCALL to METH_FASTCALL|METH_KEYWORDS and make (#1955)" This reverts commit 6969eaf. * Revert "bpo-30832: Remove own implementation for thread-local storage (#2537)" This reverts commit aa0aa04. * Revert "bpo-30764: Fix regrtest --fail-env-changed --forever (#2536)" This reverts commit 5e87592. * Revert "bpo-30822: Deduplicate ZoneInfoTest classes in test_datetime. (#2534)" This reverts commit 34b5487. * Revert "bpo-30822: Fix testing of datetime module. (#2530)" This reverts commit 98b6bc3.
Based on the patch by Guilherme Polo.