]> git.ipfire.org Git - thirdparty/git.git/commitdiff
userdiff: support Python async functions
authorJosh Holland <anowlcalledjosh@gmail.com>
Tue, 19 Nov 2019 15:08:10 +0000 (15:08 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Nov 2019 07:31:43 +0000 (16:31 +0900)
Python's async functions (declared with "async def" rather than "def")
were not being displayed in hunk headers. This commit teaches git about
the async function syntax, and adds tests for the Python userdiff regex.

Signed-off-by: Josh Holland <anowlcalledjosh@gmail.com>
Acked-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t4018/python-async-def [new file with mode: 0644]
t/t4018/python-class [new file with mode: 0644]
t/t4018/python-def [new file with mode: 0644]
t/t4018/python-indented-async-def [new file with mode: 0644]
t/t4018/python-indented-class [new file with mode: 0644]
t/t4018/python-indented-def [new file with mode: 0644]
userdiff.c

diff --git a/t/t4018/python-async-def b/t/t4018/python-async-def
new file mode 100644 (file)
index 0000000..87640e0
--- /dev/null
@@ -0,0 +1,4 @@
+async def RIGHT(pi: int = 3.14):
+    while True:
+        break
+    return ChangeMe()
diff --git a/t/t4018/python-class b/t/t4018/python-class
new file mode 100644 (file)
index 0000000..ba9e741
--- /dev/null
@@ -0,0 +1,4 @@
+class RIGHT(int, str):
+    # comment
+    # another comment
+    # ChangeMe
diff --git a/t/t4018/python-def b/t/t4018/python-def
new file mode 100644 (file)
index 0000000..e50b31b
--- /dev/null
@@ -0,0 +1,4 @@
+def RIGHT(pi: int = 3.14):
+    while True:
+        break
+    return ChangeMe()
diff --git a/t/t4018/python-indented-async-def b/t/t4018/python-indented-async-def
new file mode 100644 (file)
index 0000000..f5d0325
--- /dev/null
@@ -0,0 +1,7 @@
+class Foo:
+    async def RIGHT(self, x: int):
+        return [
+            1,
+            2,
+            ChangeMe,
+        ]
diff --git a/t/t4018/python-indented-class b/t/t4018/python-indented-class
new file mode 100644 (file)
index 0000000..19b4f35
--- /dev/null
@@ -0,0 +1,5 @@
+if TYPE_CHECKING:
+    class RIGHT:
+        # comment
+        # another comment
+        # ChangeMe
diff --git a/t/t4018/python-indented-def b/t/t4018/python-indented-def
new file mode 100644 (file)
index 0000000..208fbad
--- /dev/null
@@ -0,0 +1,7 @@
+class Foo:
+    def RIGHT(self, x: int):
+        return [
+            1,
+            2,
+            ChangeMe,
+        ]
index e74a6d402255b0eaf1022863ba30305930d29b6f..057fdcc55ca855adb9d35d25f8e1460725064375 100644 (file)
@@ -124,7 +124,7 @@ PATTERNS("php",
         "[a-zA-Z_][a-zA-Z0-9_]*"
         "|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+"
         "|[-+*/<>%&^|=!.]=|--|\\+\\+|<<=?|>>=?|===|&&|\\|\\||::|->"),
-PATTERNS("python", "^[ \t]*((class|def)[ \t].*)$",
+PATTERNS("python", "^[ \t]*((class|(async[ \t]+)?def)[ \t].*)$",
         /* -- */
         "[a-zA-Z_][a-zA-Z0-9_]*"
         "|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?"