diff options
author | Josh Holland <anowlcalledjosh@gmail.com> | 2019-11-19 15:08:10 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-11-20 16:31:43 +0900 |
commit | 077a1fda82b237c16eb10bd988650468683a94b5 (patch) | |
tree | 3dc2a504b62249c0b4a7336a58d4e9dccee14660 | |
parent | Git 2.23 (diff) | |
download | tgif-077a1fda82b237c16eb10bd988650468683a94b5.tar.xz |
userdiff: support Python async functions
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>
-rw-r--r-- | t/t4018/python-async-def | 4 | ||||
-rw-r--r-- | t/t4018/python-class | 4 | ||||
-rw-r--r-- | t/t4018/python-def | 4 | ||||
-rw-r--r-- | t/t4018/python-indented-async-def | 7 | ||||
-rw-r--r-- | t/t4018/python-indented-class | 5 | ||||
-rw-r--r-- | t/t4018/python-indented-def | 7 | ||||
-rw-r--r-- | userdiff.c | 2 |
7 files changed, 32 insertions, 1 deletions
diff --git a/t/t4018/python-async-def b/t/t4018/python-async-def new file mode 100644 index 0000000000..87640e03d2 --- /dev/null +++ b/t/t4018/python-async-def @@ -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 index 0000000000..ba9e741430 --- /dev/null +++ b/t/t4018/python-class @@ -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 index 0000000000..e50b31b0ad --- /dev/null +++ b/t/t4018/python-def @@ -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 index 0000000000..f5d03258af --- /dev/null +++ b/t/t4018/python-indented-async-def @@ -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 index 0000000000..19b4f35c4c --- /dev/null +++ b/t/t4018/python-indented-class @@ -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 index 0000000000..208fbadd2b --- /dev/null +++ b/t/t4018/python-indented-def @@ -0,0 +1,7 @@ +class Foo: + def RIGHT(self, x: int): + return [ + 1, + 2, + ChangeMe, + ] diff --git a/userdiff.c b/userdiff.c index e74a6d4022..057fdcc55c 100644 --- a/userdiff.c +++ b/userdiff.c @@ -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]?" |