Skip to content

Commit

Permalink
Remove "AppendNode", which wasn't that useful
Browse files Browse the repository at this point in the history
  • Loading branch information
isanbard committed Jan 2, 2022
1 parent 202749b commit c8d9637
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 23 deletions.
3 changes: 2 additions & 1 deletion yapf/pytree/pytree_unwrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from yapf.pytree import pytree_utils
from yapf.pytree import pytree_visitor
from yapf.pytree import split_penalty
from yapf.yapflib import format_token
from yapf.yapflib import logical_line
from yapf.yapflib import object_state
from yapf.yapflib import style
Expand Down Expand Up @@ -293,7 +294,7 @@ def DefaultLeafVisit(self, leaf):
self._StartNewLine()
elif leaf.type != grammar_token.COMMENT or leaf.value.strip():
# Add non-whitespace tokens and comments that aren't empty.
self._cur_logical_line.AppendNode(leaf)
self._cur_logical_line.AppendToken(format_token.FormatToken(leaf))


_BRACKET_MATCH = {')': '(', '}': '{', ']': '['}
Expand Down
9 changes: 3 additions & 6 deletions yapf/yapflib/format_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Pytree nodes with extra formatting information.
This is a thin wrapper around a pytree.Leaf node.
"""
"""Enhanced token information for formatting."""

import keyword
import re
Expand Down Expand Up @@ -48,13 +45,13 @@ def _TabbedContinuationAlignPadding(spaces, align_style, tab_width):


class FormatToken(object):
"""A wrapper around pytree Leaf nodes.
"""Enhanced token information for formatting.
This represents the token plus additional information useful for reformatting
the code.
Attributes:
node: The PyTree node this token represents.
node: The original token node.
next_token: The token in the logical line after this token or None if this
is the last token in the logical line.
previous_token: The token in the logical line before this token or None if
Expand Down
10 changes: 0 additions & 10 deletions yapf/yapflib/logical_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,6 @@ def AppendToken(self, token):
self.last.next_token = token
self._tokens.append(token)

def AppendNode(self, node):
"""Convenience method to append a pytree node directly.
Wraps the node with a FormatToken.
Arguments:
node: the node to append
"""
self.AppendToken(format_token.FormatToken(node))

@property
def first(self):
"""Returns the first non-whitespace token."""
Expand Down
6 changes: 0 additions & 6 deletions yapftests/logical_line_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ def testAppendToken(self):
lline.AppendToken(_MakeFormatTokenLeaf(token.RPAR, ')'))
self.assertEqual(['LPAR', 'RPAR'], [tok.name for tok in lline.tokens])

def testAppendNode(self):
lline = logical_line.LogicalLine(0)
lline.AppendNode(pytree.Leaf(token.LPAR, '('))
lline.AppendNode(pytree.Leaf(token.RPAR, ')'))
self.assertEqual(['LPAR', 'RPAR'], [tok.name for tok in lline.tokens])


class LogicalLineFormattingInformationTest(yapf_test_helper.YAPFTest):

Expand Down

0 comments on commit c8d9637

Please sign in to comment.