[issue38307] Add .end_lineno attribute to pyclbr _Objects

Terry J. Reedy report at bugs.python.org
Wed Jan 27 17:34:04 EST 2021


Terry J. Reedy <tjreedy at udel.edu> added the comment:

The answer, Aviral discovered,  is that current ast nodes have end_lineno attributes, so the patch amounts to consistently copying them.

I don't understand Aviral's use case either, but an item on my IDLE wish list is to be able to move class and function definitions within a file by moving the Class and Function entries within the browser tree.  This requieres end lines and having it be an attribute is easier and more accurate than recalculating it.  Merely clicking on an entry could highlight the whole definition.  Other people might think of other uses.

An issue in the patch is inserting parameter 'end_line' after 'line'.  Normally, new parameters have to go at the end, but:

1. Inserting 'end_line' after 'line' makes the code easier to read.

2. The parameter or parameters at the end have default values.  If we added 'end_line=None', we would have to consider what to do when it is omitted.

3. https://docs.python.org/3/library/pyclbr.html#module-pyclbr, which I rewrote in 2017, documents readline and readline_ex as the public call interface.  They return a hierarchical structure that includes Functions and Classes in the dict values.  Their signatures are intentionally omitted and the attributes are only listed after saying "Users are not expected to create instances of these classes."

I posted "What is the pyclbr public API" to pydev asking about this issue.

----------
nosy: +terry.reedy
title: Provide Class' end line in pyclbr module -> Add .end_lineno attribute to pyclbr _Objects
versions: +Python 3.10 -Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38307>
_______________________________________


More information about the Python-bugs-list mailing list