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.
The implementation of the new backtracking logic depends heavily on deepcopying the current state of the parser before seeing one of the new keywords, which by default is an very expensive operations. On my system, formatting these 3 files takes 1.3 seconds.
```
$ touch tests/data/pattern_matching_*; time python -m black -tpy310 tests/data/pattern_matching_* 19ms
All done! ✨ 🍰 ✨
3 files left unchanged.
python -m black -tpy310 tests/data/pattern_matching_* 2,09s user 0,04s system 157% cpu 1,357 total
```
which can be optimized 3X if we integrate the existing copying logic (`clone`) to the deepcopy system;
```
$ touch tests/data/pattern_matching_*; time python -m black -tpy310 tests/data/pattern_matching_* 1ms
All done! ✨ 🍰 ✨
3 files left unchanged.
python -m black -tpy310 tests/data/pattern_matching_* 0,66s user 0,02s system 147% cpu 0,464 total
```
This still might have some potential, but that would be way trickier than this initial patch.
return _type_reprs.setdefault(type_num, type_num)
return _type_reprs.setdefault(type_num, type_num)
+_P = TypeVar("_P", bound="Base")
NL = Union["Node", "Leaf"]
Context = Tuple[Text, Tuple[int, int]]
NL = Union["Node", "Leaf"]
Context = Tuple[Text, Tuple[int, int]]
"""
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.
def clone(self: _P) -> _P:
"""
Return a cloned (deep) copy of self.
match something:
case [a as b]:
print(b)
match something:
case [a as b]:
print(b)
print(b)
case Point(int() as x, int() as y):
print(x, y)
print(b)
case Point(int() as x, int() as y):
print(x, y)
+
+
+match = 1
+case: int = re.match(something)
+
+match re.match(case):
+ case type("match", match):
+ pass
+ case match:
+ pass
+
+
+def func(match: case, case: match) -> case:
+ match Something():
+ case another:
+ ...
+ case func(match, case):
+ ...