]> git.madduck.net Git - etc/vim.git/commitdiff

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:

Support nested lambdas in BracketTracker
authorŁukasz Langa <lukasz@langa.pl>
Wed, 9 May 2018 03:59:18 +0000 (20:59 -0700)
committerŁukasz Langa <lukasz@langa.pl>
Wed, 9 May 2018 04:57:09 +0000 (21:57 -0700)
black.py
tests/expression.diff
tests/expression.py

index 00d5758dd802e9a3a110c0380d32c3f287c1ce44..c2363e4b950a34509508b3fc894bd32fce4e36f0 100644 (file)
--- a/black.py
+++ b/black.py
@@ -647,8 +647,8 @@ class BracketTracker:
     bracket_match: Dict[Tuple[Depth, NodeType], Leaf] = Factory(dict)
     delimiters: Dict[LeafID, Priority] = Factory(dict)
     previous: Optional[Leaf] = None
-    _for_loop_variable: bool = False
-    _lambda_arguments: bool = False
+    _for_loop_variable: int = 0
+    _lambda_arguments: int = 0
 
     def mark(self, leaf: Leaf) -> None:
         """Mark `leaf` with bracket-related metadata. Keep track of delimiters.
@@ -710,7 +710,7 @@ class BracketTracker:
         """
         if leaf.type == token.NAME and leaf.value == "for":
             self.depth += 1
-            self._for_loop_variable = True
+            self._for_loop_variable += 1
             return True
 
         return False
@@ -719,7 +719,7 @@ class BracketTracker:
         """See `maybe_increment_for_loop_variable` above for explanation."""
         if self._for_loop_variable and leaf.type == token.NAME and leaf.value == "in":
             self.depth -= 1
-            self._for_loop_variable = False
+            self._for_loop_variable -= 1
             return True
 
         return False
@@ -732,7 +732,7 @@ class BracketTracker:
         """
         if leaf.type == token.NAME and leaf.value == "lambda":
             self.depth += 1
-            self._lambda_arguments = True
+            self._lambda_arguments += 1
             return True
 
         return False
@@ -741,7 +741,7 @@ class BracketTracker:
         """See `maybe_increment_lambda_arguments` above for explanation."""
         if self._lambda_arguments and leaf.type == token.COLON:
             self.depth -= 1
-            self._lambda_arguments = False
+            self._lambda_arguments -= 1
             return True
 
         return False
index 2af955c88acc125913682f96574d09f308b357db..3d170ddbb3cfe093164803fc3a87e99e6b1159d2 100644 (file)
@@ -11,7 +11,7 @@
  True
  False
  1
-@@ -29,61 +29,83 @@
+@@ -29,62 +29,84 @@
  ~great
  +value
  -1
  lambda a, b, c=True: a
 -lambda a, b, c=True, *, d=(1 << v2), e='str': a
 -lambda a, b, c=True, *vararg, d=(v1 << 2), e='str', **kwargs: a + b
--foo = (lambda port_id, ignore_missing: {"port1": port1_resource, "port2": port2_resource}[port_id])
 +lambda a, b, c=True, *, d=(1 << v2), e="str": a
 +lambda a, b, c=True, *vararg, d=(v1 << 2), e="str", **kwargs: a + b
+ manylambdas = lambda x=lambda y=lambda z=1: z: y(): x()
+-foo = (lambda port_id, ignore_missing: {"port1": port1_resource, "port2": port2_resource}[port_id])
 +foo = lambda port_id, ignore_missing: {
 +    "port1": port1_resource, "port2": port2_resource
 +}[
  call(**self.screen_kwargs)
  call(b, **self.screen_kwargs)
  lukasz.langa.pl
-@@ -92,11 +114,11 @@
+@@ -93,11 +115,11 @@
  1.0 .real
  ....__class__
  list[str]
  ]
  slice[0]
  slice[0:1]
-@@ -123,103 +145,140 @@
+@@ -124,103 +146,140 @@
  numpy[-(c + 1) :, d]
  numpy[:, l[-2]]
  numpy[:, ::-1]
index 82d9dfa719d9c9ac6ccc34b78547ec09cd13689a..63f6a4f9632f42429a7d2c378cc413f8d422a431 100644 (file)
@@ -37,6 +37,7 @@ lambda a=True: a
 lambda a, b, c=True: a
 lambda a, b, c=True, *, d=(1 << v2), e='str': a
 lambda a, b, c=True, *vararg, d=(v1 << 2), e='str', **kwargs: a + b
+manylambdas = lambda x=lambda y=lambda z=1: z: y(): x()
 foo = (lambda port_id, ignore_missing: {"port1": port1_resource, "port2": port2_resource}[port_id])
 1 if True else 2
 str or None if True else str or bytes or None
@@ -266,6 +267,7 @@ lambda a=True: a
 lambda a, b, c=True: a
 lambda a, b, c=True, *, d=(1 << v2), e="str": a
 lambda a, b, c=True, *vararg, d=(v1 << 2), e="str", **kwargs: a + b
+manylambdas = lambda x=lambda y=lambda z=1: z: y(): x()
 foo = lambda port_id, ignore_missing: {
     "port1": port1_resource, "port2": port2_resource
 }[