{"thread":{"id":"52233","subject":"[PATCH] userdiff: support Python async functions","startedAt":"2019-11-11T01:02:43Z","lastAt":"2019-11-12T04:43:16Z","messageCount":4,"participants":["Josh Holland","Junio C Hamano","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"385852","messageId":"20191111010148.2812-1-anowlcalledjosh@gmail.com","threadId":"52233","inReplyTo":null,"subject":"[PATCH] userdiff: support Python async functions","fromName":"Josh Holland","fromEmail":"anowlcalledjosh@gmail.com","sentAt":"2019-11-11T01:01:48Z","receivedAt":"2019-11-11T01:02:43Z","isPatch":true,"sender":{"key":"anowlcalledjosh@gmail.com","avatar":null},"body":"Python's async functions (declared with \"async def\" rather than \"def\")\nwere not being displayed in hunk headers. This commit teaches git about\nthe async function syntax, and adds tests for the Python userdiff regex.\n\nSigned-off-by: Josh Holland <anowlcalledjosh@gmail.com>\n---\n t/t4018/python-async-def | 4 ++++\n t/t4018/python-class     | 4 ++++\n t/t4018/python-def       | 4 ++++\n userdiff.c               | 2 +-\n 4 files changed, 13 insertions(+), 1 deletion(-)\n create mode 100644 t/t4018/python-async-def\n create mode 100644 t/t4018/python-class\n create mode 100644 t/t4018/python-def\n\ndiff --git a/t/t4018/python-async-def b/t/t4018/python-async-def\nnew file mode 100644\nindex 000000000..87640e03d\n--- /dev/null\n+++ b/t/t4018/python-async-def\n@@ -0,0 +1,4 @@\n+async def RIGHT(pi: int = 3.14):\n+    while True:\n+        break\n+    return ChangeMe()\ndiff --git a/t/t4018/python-class b/t/t4018/python-class\nnew file mode 100644\nindex 000000000..ba9e74143\n--- /dev/null\n+++ b/t/t4018/python-class\n@@ -0,0 +1,4 @@\n+class RIGHT(int, str):\n+    # comment\n+    # another comment\n+    # ChangeMe\ndiff --git a/t/t4018/python-def b/t/t4018/python-def\nnew file mode 100644\nindex 000000000..e50b31b0a\n--- /dev/null\n+++ b/t/t4018/python-def\n@@ -0,0 +1,4 @@\n+def RIGHT(pi: int = 3.14):\n+    while True:\n+        break\n+    return ChangeMe()\ndiff --git a/userdiff.c b/userdiff.c\nindex e74a6d402..057fdcc55 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -124,7 +124,7 @@ PATTERNS(\"php\",\n \t \"[a-zA-Z_][a-zA-Z0-9_]*\"\n \t \"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+\"\n \t \"|[-+*/<>%&^|=!.]=|--|\\\\+\\\\+|<<=?|>>=?|===|&&|\\\\|\\\\||::|->\"),\n-PATTERNS(\"python\", \"^[ \\t]*((class|def)[ \\t].*)$\",\n+PATTERNS(\"python\", \"^[ \\t]*((class|(async[ \\t]+)?def)[ \\t].*)$\",\n \t /* -- */\n \t \"[a-zA-Z_][a-zA-Z0-9_]*\"\n \t \"|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?\"\n-- \n2.24.0\n\n"},{"id":"385862","messageId":"xmqqpnhzi1so.fsf@gitster-ct.c.googlers.com","threadId":"52233","inReplyTo":"20191111010148.2812-1-anowlcalledjosh@gmail.com","subject":"Re: [PATCH] userdiff: support Python async functions","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-11-11T02:28:55Z","receivedAt":"2019-11-11T02:29:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Josh Holland <anowlcalledjosh@gmail.com> writes:\n\n> Python's async functions (declared with \"async def\" rather than \"def\")\n> were not being displayed in hunk headers. This commit teaches git about\n> the async function syntax, and adds tests for the Python userdiff regex.\n>\n> Signed-off-by: Josh Holland <anowlcalledjosh@gmail.com>\n> ---\n>  t/t4018/python-async-def | 4 ++++\n>  t/t4018/python-class     | 4 ++++\n>  t/t4018/python-def       | 4 ++++\n>  userdiff.c               | 2 +-\n>  4 files changed, 13 insertions(+), 1 deletion(-)\n>  create mode 100644 t/t4018/python-async-def\n>  create mode 100644 t/t4018/python-class\n>  create mode 100644 t/t4018/python-def\n\nIt seems that there were no test patterns for Python ;-) The change\nto userdiff.c part (i.e. \"where we used to expect 'def', we now\nallow it to be prefixed with an optional 'async' plus whitespace\")\nmakes sense.\n\nThanks, will queue.\n"},{"id":"385916","messageId":"f8a729c6-7b27-cac8-815e-b5c02a5c7b44@kdbg.org","threadId":"52233","inReplyTo":"20191111010148.2812-1-anowlcalledjosh@gmail.com","subject":"Re: [PATCH] userdiff: support Python async functions","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2019-11-11T17:27:24Z","receivedAt":"2019-11-11T17:27:32Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 11.11.19 um 02:01 schrieb Josh Holland:\n> Python's async functions (declared with \"async def\" rather than \"def\")\n> were not being displayed in hunk headers. This commit teaches git about\n> the async function syntax, and adds tests for the Python userdiff regex.\n> \n> Signed-off-by: Josh Holland <anowlcalledjosh@gmail.com>\n> ---\n>  t/t4018/python-async-def | 4 ++++\n>  t/t4018/python-class     | 4 ++++\n>  t/t4018/python-def       | 4 ++++\n>  userdiff.c               | 2 +-\n>  4 files changed, 13 insertions(+), 1 deletion(-)\n>  create mode 100644 t/t4018/python-async-def\n>  create mode 100644 t/t4018/python-class\n>  create mode 100644 t/t4018/python-def\n> \n> diff --git a/t/t4018/python-async-def b/t/t4018/python-async-def\n> new file mode 100644\n> index 000000000..87640e03d\n> --- /dev/null\n> +++ b/t/t4018/python-async-def\n> @@ -0,0 +1,4 @@\n> +async def RIGHT(pi: int = 3.14):\n> +    while True:\n> +        break\n> +    return ChangeMe()\n> diff --git a/t/t4018/python-class b/t/t4018/python-class\n> new file mode 100644\n> index 000000000..ba9e74143\n> --- /dev/null\n> +++ b/t/t4018/python-class\n> @@ -0,0 +1,4 @@\n> +class RIGHT(int, str):\n> +    # comment\n> +    # another comment\n> +    # ChangeMe\n> diff --git a/t/t4018/python-def b/t/t4018/python-def\n> new file mode 100644\n> index 000000000..e50b31b0a\n> --- /dev/null\n> +++ b/t/t4018/python-def\n> @@ -0,0 +1,4 @@\n> +def RIGHT(pi: int = 3.14):\n> +    while True:\n> +        break\n> +    return ChangeMe()\n\nThank you for providing test cases for Python.\n\nI have one gripe with this set of test, though: They do not demonstrate\nthat the Python-specific pattern is better than the default pattern. In\nfact, if you remove the Python patterns from userdiff.c, you will\nobserve that these tests still pass.\n\nThe one thing that the language specific pattern would do better than\nthe default is that it picks up indented text. Could we have a test case\nor two that show that it indeed does?\n\n> diff --git a/userdiff.c b/userdiff.c\n> index e74a6d402..057fdcc55 100644\n> --- a/userdiff.c\n> +++ b/userdiff.c\n> @@ -124,7 +124,7 @@ PATTERNS(\"php\",\n>  \t \"[a-zA-Z_][a-zA-Z0-9_]*\"\n>  \t \"|[-+0-9.e]+|0[xXbB]?[0-9a-fA-F]+\"\n>  \t \"|[-+*/<>%&^|=!.]=|--|\\\\+\\\\+|<<=?|>>=?|===|&&|\\\\|\\\\||::|->\"),\n> -PATTERNS(\"python\", \"^[ \\t]*((class|def)[ \\t].*)$\",\n> +PATTERNS(\"python\", \"^[ \\t]*((class|(async[ \\t]+)?def)[ \\t].*)$\",\n>  \t /* -- */\n>  \t \"[a-zA-Z_][a-zA-Z0-9_]*\"\n>  \t \"|[-+0-9.e]+[jJlL]?|0[xX]?[0-9a-fA-F]+[lL]?\"\n> \n\n-- Hannes\n"},{"id":"385977","messageId":"xmqqtv79g0wx.fsf@gitster-ct.c.googlers.com","threadId":"52233","inReplyTo":"f8a729c6-7b27-cac8-815e-b5c02a5c7b44@kdbg.org","subject":"Re: [PATCH] userdiff: support Python async functions","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-11-12T04:43:10Z","receivedAt":"2019-11-12T04:43:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Sixt <j6t@kdbg.org> writes:\n\n>> ...\n>> @@ -0,0 +1,4 @@\n>> +def RIGHT(pi: int = 3.14):\n>> +    while True:\n>> +        break\n>> +    return ChangeMe()\n>\n> Thank you for providing test cases for Python.\n>\n> I have one gripe with this set of test, though: They do not demonstrate\n> that the Python-specific pattern is better than the default pattern. In\n> fact, if you remove the Python patterns from userdiff.c, you will\n> observe that these tests still pass.\n>\n> The one thing that the language specific pattern would do better than\n> the default is that it picks up indented text. Could we have a test case\n> or two that show that it indeed does?\n\nGood point.  A method \"def\" inside a \"class\" would be one level\nindented; I am not sure if it is a kosher style to have \"if\" at the\nunindented top-level, whose body conditionally defines a \"class\",\nbut such a class definition would also be indented, I guess.\n\nThanks.\n\n"}]}