Terry J. Reedy <tjre...@udel.edu> added the comment:

Let's consider the todo questions at the end of the class Parser code.
    # XXX - is this used?
    lastopenbracketpos = None

    def get_last_open_bracket_pos(self):
        "Return index of last open bracket or None."
        return self.lastopenbracketpos

    # XXX - is this used?
    stmt_bracketing = None

    def get_last_stmt_bracketing(self):
        """Return a tuple of the structure of the bracketing of the last
        interesting statement.

        Tuple is in the format defined in _study2().
        return self.stmt_bracketing

get_last_open_bracket_pos is not called anywhere. TODO remove it.
get_last_stmt_bracketing is called once in hyperparser and could be replaced 
there by 'parser._study2(); parser.stmt_bracketing'. TODO?

Integer lastopenbracketpos is only conditionally set as an instance attribute, 
which masks the class attribute, in _study2 with
        if stack:  # of opener indices
            self.lastopenbracketpos = stack[-1]

However, self.lastopenbracketpos in only accessed (as 'j') in  
compute_bracket_indent, which is only called when a statement is continued to 
the next line because of an open bracket.  Indeed, the call is guarded by 
        assert self.continuation == C_BRACKET  # TODO: move up
So the class binding is never used because it is always masked bebore being 
accessed.  Its value None would raise if it were. (That may have been 
intentional.)  TODO remove it.

Stopping here would break the current tests.  We could make _study2 return the 
index and change test according. Or we can make _study2 always set the 
attribute with (TODO this)
        self.lastopenbracketpos = stack[-1] if stack else None
and remove the workaround test lines:
            p.lastopenbracketpos = None

Since _study2 unconditionally sets stmt_bracketing as an instance attribute with
        self.stmt_bracketing = tuple(bracketing)
and self.stmt_bracketing is only accessed, in the get function above (or 
possibly directly in the future), after such a call, its class setting is also 
useless.  TODO remove it.  No test change needed.


Python tracker <rep...@bugs.python.org>
Python-bugs-list mailing list

Reply via email to