from typing import (
Any,
- Callable,
Dict,
Iterator,
List,
import sys
from io import StringIO
-HUGE: int = 0x7fffffff # maximum repeat count, default max
+HUGE: int = 0x7FFFFFFF # maximum repeat count, default max
_type_reprs: Dict[int, Union[Text, int]] = {}
return _type_reprs.setdefault(type_num, type_num)
-_P = TypeVar("_P")
+_P = TypeVar("_P", bound="Base")
NL = Union["Node", "Leaf"]
Context = Tuple[Text, Tuple[int, int]]
return NotImplemented
return self._eq(other)
- __hash__ = None # type: Any # For Py3 compatibility.
-
@property
def prefix(self) -> Text:
raise NotImplementedError
"""
raise NotImplementedError
+ def __deepcopy__(self: _P, memo: Any) -> _P:
+ return self.clone()
+
def clone(self: _P) -> _P:
"""
Return a cloned (deep) copy of self.
This reproduces the input source exactly.
"""
- return self.prefix + str(self.value)
+ return self._prefix + str(self.value)
def _eq(self, other) -> bool:
"""Compare two nodes for equality."""
newcontent = list(content)
for i, item in enumerate(newcontent):
assert isinstance(item, BasePattern), (i, item)
- if isinstance(item, WildcardPattern):
- self.wildcards = True
+ # I don't even think this code is used anywhere, but it does cause
+ # unreachable errors from mypy. This function's signature does look
+ # odd though *shrug*.
+ if isinstance(item, WildcardPattern): # type: ignore[unreachable]
+ self.wildcards = True # type: ignore[unreachable]
self.type = type
self.content = newcontent
self.name = name
r.update(r0)
r.update(r1)
yield c0 + c1, r
-
-
-_Convert = Callable[[Grammar, RawNode], Any]