]>
git.madduck.net Git - etc/vim.git/blobdiff - src/blib2to3/pytree.py
madduck's git repository
Every one of the projects in this repository is available at the canonical
URL git://git.madduck.net/madduck/pub/<projectpath> — see
each project's metadata for the exact URL.
All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@ git. madduck. net .
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
SSH access, as well as push access can be individually
arranged .
If you use my repositories frequently, consider adding the following
snippet to ~/.gitconfig and using the third clone URL listed for each
project:
[url "git://git.madduck.net/madduck/"]
insteadOf = madduck:
There's also a pattern matching implementation here.
"""
There's also a pattern matching implementation here.
"""
-# mypy: allow-untyped-defs
+# mypy: allow-untyped-defs, allow-incomplete-defs
from typing import (
Any,
from typing import (
Any,
"""
return "".join(map(str, self.children))
"""
return "".join(map(str, self.children))
- def _eq(self, other) -> bool:
+ def _eq(self, other: Base ) -> bool:
"""Compare two nodes for equality."""
return (self.type, self.children) == (other.type, other.children)
"""Compare two nodes for equality."""
return (self.type, self.children) == (other.type, other.children)
return self.children[0].prefix
@prefix.setter
return self.children[0].prefix
@prefix.setter
- def prefix(self, prefix) -> None:
+ def prefix(self, prefix: Text ) -> None:
if self.children:
self.children[0].prefix = prefix
if self.children:
self.children[0].prefix = prefix
"""
return self._prefix + str(self.value)
"""
return self._prefix + str(self.value)
- def _eq(self, other) -> bool:
+ def _eq(self, other: "Leaf" ) -> bool:
"""Compare two nodes for equality."""
return (self.type, self.value) == (other.type, other.value)
"""Compare two nodes for equality."""
return (self.type, self.value) == (other.type, other.value)
self.value,
(self.prefix, (self.lineno, self.column)),
fixers_applied=self.fixers_applied,
self.value,
(self.prefix, (self.lineno, self.column)),
fixers_applied=self.fixers_applied,
- opening_bracket=self.opening_bracket,
)
def leaves(self) -> Iterator["Leaf"]:
)
def leaves(self) -> Iterator["Leaf"]:
return self._prefix
@prefix.setter
return self._prefix
@prefix.setter
- def prefix(self, prefix) -> None:
+ def prefix(self, prefix: Text ) -> None:
self.changed()
self._prefix = prefix
self.changed()
self._prefix = prefix
self.content = content
self.name = name
self.content = content
self.name = name
- def match(self, node: NL, results=None):
+ def match(self, node: NL, results=None) -> bool :
"""Override match() to insist on a leaf node."""
if not isinstance(node, Leaf):
return False
"""Override match() to insist on a leaf node."""
if not isinstance(node, Leaf):
return False
if isinstance(item, WildcardPattern): # type: ignore[unreachable]
self.wildcards = True # type: ignore[unreachable]
self.type = type
if isinstance(item, WildcardPattern): # type: ignore[unreachable]
self.wildcards = True # type: ignore[unreachable]
self.type = type
- self.content = newcontent
+ self.content = newcontent # TODO: this is unbound when content is None
self.name = name
def _submatch(self, node, results=None) -> bool:
self.name = name
def _submatch(self, node, results=None) -> bool:
class NegatedPattern(BasePattern):
class NegatedPattern(BasePattern):
- def __init__(self, content: Optional[Any ] = None) -> None:
+ def __init__(self, content: Optional[BasePattern ] = None) -> None:
# We only match an empty sequence of nodes in its entirety
return len(nodes) == 0
# We only match an empty sequence of nodes in its entirety
return len(nodes) == 0
- def generate_matches(self, nodes) -> Iterator[Tuple[int, _Results]]:
+ def generate_matches(self, nodes: List[NL] ) -> Iterator[Tuple[int, _Results]]:
if self.content is None:
# Return a match if there is an empty sequence
if len(nodes) == 0:
if self.content is None:
# Return a match if there is an empty sequence
if len(nodes) == 0: