On Wed, Jun 12, 2019 at 6:59 AM vitalije <vitali...@gmail.com> wrote:
> I am not sure what were your intentions for find-missing-docstrings > command. > It was mostly to play with live objects. Pylint's "missing-docstring" test creates clickable links, so for actually adding docstrings pylint is the best tool. However, it was fun so see that a simple script discovers missing docstrings in about 1/10 sec. I assume you found out that it is impossible to use live objects in > general, but useful for searching in Leo's own code. > Exactly. Here is my script that searches Leo outline for methods and classes with > missing docstrings: > > import timeit > def has_docstring(lines, n): > '''returns True if function/method/class whose definition > starts on n-th line in lines has a docstring''' > for line in lines[n:]: > s = line.strip() > if not s or s.startswith('#'): continue > return s.startswith(('"', "'")) > > def is_a_definition(line): > return line.startswith(('def ', 'class ')) and not line.partition(' > ')[2].startswith('__init__') > # I guess it is useful to skip __init__ methods because their docstring > # is usually docstring of the class > > def find_all_missing_docstrings(): > for p in c.all_positions(): > lines = p.b.split('\n') > for i, line in enumerate(lines, start=1): > if is_a_definition(line) and not has_docstring(lines, i): > yield p, i > def f(): > return list(find_all_missing_docstrings()) > def nlink(p, i): > return "%s,%d"%(p.get_UNL(with_proto=True, > with_count=True, > with_index=True),i) > c.frame.log.clearTab('Log') > t1 = timeit.timeit(f, number=20)/20 * 1000 > g.es('finished in %.2fms'%t1) > res = f() > g.es(len(res)) > p, i = res[3117] > lines = p.b.split('\n') > g.es(lines[i-1], nodeLink=nlink(p, i)) > > > On my machine in my version of LeoPy.leo this script finds about 3737 > missing docstrings in 122.28ms. > The script will write to Log pane 3117-th occurrence with the clickable > link. I guess it would take long to write all the occurrences in the Log > pane, so I've chosen one random item. > Excellent! I'll try it out. It looks like it will find missing docstring in any .leo file. Edward -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to leo-editor+unsubscr...@googlegroups.com. To post to this group, send email to leo-editor@googlegroups.com. Visit this group at https://groups.google.com/group/leo-editor. To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/CAMF8tS2wCorOoSKRBsUa9yVTdXA%2BBXzh5HXrN-BSjv4R7Rq2Og%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.