[issue20827] IDLE : Display function argument list in ClassBrowser

Terry J. Reedy report at bugs.python.org
Wed Mar 12 03:22:40 CET 2014


Terry J. Reedy added the comment:

ClassBrowser has multiple problems. I agree with the goal of given signatures. But the patch has these problems.

1. Idle is getting out of the business of formatting signatures. If we use inspect, '(...)' should simply be replaced (in 3.3+) by str(inspect.signature(ob)). (I plan to change calltips to do this instead of using two older inspect functions.)  Using inspect creates the problems of getting ob.

2 It we go that route, the module should be imported just once, not once per tree item.  Each class should be retrieved just once, not once per method. 

3. The patch does not handle nested classes (or their methods). If nested classes are found in the dictionary of 'methods' of the enclosing class, this should be possible to keep track of.

I believe the intent of the comment in the ClassBrowser source was to use the 'def' line number provided by pyclbr to find the open and close parentheses of the header and copy the stuff in between. The open ( after the name is easy. Finding the closing ) is easy in the simple case, but hard in the general case because of nested parens in expressions and unmatched paren in strings and comments. Or because of ':' being used in dict pairs and in strings and comments, as well as terminating the header. I see why it was not done.

On the other hand, if the output of tokenize.tokenize is used, as in pyclbr, then matching parens is easy, as strings and comments are distinguished from ( and ) as operators. This suggests that extracting the signature string belongs in pyclbr.

I am tempted to pull the code that parses the token stream out of pyclbr and adapt it to our uses. We could easily make a Text widget 'readline' so tokenize could get lines directly from the text widget. (We really should do that anyway for iterating through in-memory text. Format: string trailing whitespace already does that.) That would make most of this suggested todo "- add popup menu with more options (e.g. doc strings, base classes, imports)" possible. Docstrings could be kept as a view objest with start and stop positions until requested.

--
The current main() has itself multiple problems. It does not work because PyShell.flist does not exist when it is called (the same attribute reference does work in the OnDoubleClick methods.

I presume that the backup line 'file = sys.argv[0]' is for running the file as main from the command line, as a test. That would not work on my Windows systems because x.py is not executable.

Since 'if sys.stdin is sys.__stdin__:' is not currently try, the mainloop does not run anyway.

Issue #18104 is about human-run tests. I have not yet decided exactly what to do, but I do not want to call them 'main' in the module file itself, and probably want to move them elsewhwere.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20827>
_______________________________________


More information about the Python-bugs-list mailing list