git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] userdiff: support Python async functions
@ 2019-11-11  1:01 Josh Holland
  2019-11-11  2:28 ` Junio C Hamano
  2019-11-11 17:27 ` Johannes Sixt
  0 siblings, 2 replies; 4+ messages in thread
From: Josh Holland @ 2019-11-11  1:01 UTC (permalink / raw)
  To: git; +Cc: Josh Holland

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>
---
 t/t4018/python-async-def | 4 ++++
 t/t4018/python-class     | 4 ++++
 t/t4018/python-def       | 4 ++++
 userdiff.c               | 2 +-
 4 files changed, 13 insertions(+), 1 deletion(-)
 create mode 100644 t/t4018/python-async-def
 create mode 100644 t/t4018/python-class
 create mode 100644 t/t4018/python-def

diff --git a/t/t4018/python-async-def b/t/t4018/python-async-def
new file mode 100644
index 000000000..87640e03d
--- /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 000000000..ba9e74143
--- /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 000000000..e50b31b0a
--- /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/userdiff.c b/userdiff.c
index e74a6d402..057fdcc55 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]?"
-- 
2.24.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] userdiff: support Python async functions
  2019-11-11  1:01 [PATCH] userdiff: support Python async functions Josh Holland
@ 2019-11-11  2:28 ` Junio C Hamano
  2019-11-11 17:27 ` Johannes Sixt
  1 sibling, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2019-11-11  2:28 UTC (permalink / raw)
  To: Josh Holland; +Cc: git

Josh Holland <anowlcalledjosh@gmail.com> writes:

> 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>
> ---
>  t/t4018/python-async-def | 4 ++++
>  t/t4018/python-class     | 4 ++++
>  t/t4018/python-def       | 4 ++++
>  userdiff.c               | 2 +-
>  4 files changed, 13 insertions(+), 1 deletion(-)
>  create mode 100644 t/t4018/python-async-def
>  create mode 100644 t/t4018/python-class
>  create mode 100644 t/t4018/python-def

It seems that there were no test patterns for Python ;-) The change
to userdiff.c part (i.e. "where we used to expect 'def', we now
allow it to be prefixed with an optional 'async' plus whitespace")
makes sense.

Thanks, will queue.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] userdiff: support Python async functions
  2019-11-11  1:01 [PATCH] userdiff: support Python async functions Josh Holland
  2019-11-11  2:28 ` Junio C Hamano
@ 2019-11-11 17:27 ` Johannes Sixt
  2019-11-12  4:43   ` Junio C Hamano
  1 sibling, 1 reply; 4+ messages in thread
From: Johannes Sixt @ 2019-11-11 17:27 UTC (permalink / raw)
  To: Josh Holland; +Cc: git, Junio C Hamano

Am 11.11.19 um 02:01 schrieb Josh Holland:
> 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>
> ---
>  t/t4018/python-async-def | 4 ++++
>  t/t4018/python-class     | 4 ++++
>  t/t4018/python-def       | 4 ++++
>  userdiff.c               | 2 +-
>  4 files changed, 13 insertions(+), 1 deletion(-)
>  create mode 100644 t/t4018/python-async-def
>  create mode 100644 t/t4018/python-class
>  create mode 100644 t/t4018/python-def
> 
> diff --git a/t/t4018/python-async-def b/t/t4018/python-async-def
> new file mode 100644
> index 000000000..87640e03d
> --- /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 000000000..ba9e74143
> --- /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 000000000..e50b31b0a
> --- /dev/null
> +++ b/t/t4018/python-def
> @@ -0,0 +1,4 @@
> +def RIGHT(pi: int = 3.14):
> +    while True:
> +        break
> +    return ChangeMe()

Thank you for providing test cases for Python.

I have one gripe with this set of test, though: They do not demonstrate
that the Python-specific pattern is better than the default pattern. In
fact, if you remove the Python patterns from userdiff.c, you will
observe that these tests still pass.

The one thing that the language specific pattern would do better than
the default is that it picks up indented text. Could we have a test case
or two that show that it indeed does?

> diff --git a/userdiff.c b/userdiff.c
> index e74a6d402..057fdcc55 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]?"
> 

-- Hannes

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] userdiff: support Python async functions
  2019-11-11 17:27 ` Johannes Sixt
@ 2019-11-12  4:43   ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2019-11-12  4:43 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Josh Holland, git

Johannes Sixt <j6t@kdbg.org> writes:

>> ...
>> @@ -0,0 +1,4 @@
>> +def RIGHT(pi: int = 3.14):
>> +    while True:
>> +        break
>> +    return ChangeMe()
>
> Thank you for providing test cases for Python.
>
> I have one gripe with this set of test, though: They do not demonstrate
> that the Python-specific pattern is better than the default pattern. In
> fact, if you remove the Python patterns from userdiff.c, you will
> observe that these tests still pass.
>
> The one thing that the language specific pattern would do better than
> the default is that it picks up indented text. Could we have a test case
> or two that show that it indeed does?

Good point.  A method "def" inside a "class" would be one level
indented; I am not sure if it is a kosher style to have "if" at the
unindented top-level, whose body conditionally defines a "class",
but such a class definition would also be indented, I guess.

Thanks.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-11-12  4:43 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-11  1:01 [PATCH] userdiff: support Python async functions Josh Holland
2019-11-11  2:28 ` Junio C Hamano
2019-11-11 17:27 ` Johannes Sixt
2019-11-12  4:43   ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).