* [PATCH v2] userdiff: support Python async functions
@ 2019-11-19 15:08 Josh Holland
2019-11-20 3:59 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Josh Holland @ 2019-11-19 15:08 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>
---
This patch now includes tests for indented declarations, as well as the
unindented versions which were present before. Apologies for the delay
in preparing this patch.
t/t4018/python-async-def | 4 ++++
t/t4018/python-class | 4 ++++
t/t4018/python-def | 4 ++++
t/t4018/python-indented-async-def | 7 +++++++
t/t4018/python-indented-class | 5 +++++
t/t4018/python-indented-def | 7 +++++++
userdiff.c | 2 +-
7 files changed, 32 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
create mode 100644 t/t4018/python-indented-async-def
create mode 100644 t/t4018/python-indented-class
create mode 100644 t/t4018/python-indented-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/t/t4018/python-indented-async-def b/t/t4018/python-indented-async-def
new file mode 100644
index 000000000..f5d03258a
--- /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 000000000..19b4f35c4
--- /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 000000000..208fbadd2
--- /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 e187d356f..3fd324e61 100644
--- a/userdiff.c
+++ b/userdiff.c
@@ -133,7 +133,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] 3+ messages in thread
* Re: [PATCH v2] userdiff: support Python async functions
2019-11-19 15:08 [PATCH v2] userdiff: support Python async functions Josh Holland
@ 2019-11-20 3:59 ` Junio C Hamano
2019-11-20 6:48 ` Johannes Sixt
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2019-11-20 3:59 UTC (permalink / raw)
To: Josh Holland; +Cc: git
Josh Holland <anowlcalledjosh@gmail.com> writes:
> This patch now includes tests for indented declarations, as well as the
> unindented versions which were present before.
Very much appreciated.
I wondered if something like
diff --git a/t/t4018/python-indented-async-def b/t/t4018/python-indented-async-def
index f5d03258af..567c1dafcb 100644
--- a/t/t4018/python-indented-async-def
+++ b/t/t4018/python-indented-async-def
@@ -1,3 +1,6 @@
+async def not_this_one(self):
+ return []
+
class Foo:
async def RIGHT(self, x: int):
return [
would further help, but if a breakage makes us ignore a start of
definition that is indented, we would hit "class Foo:" you added
and notice such a breakage anyway, without additional definition
before it. So I think what we see in this patch is good.
Thanks.
> ...
> t/t4018/python-indented-async-def | 7 +++++++
> ...
> diff --git a/t/t4018/python-indented-async-def b/t/t4018/python-indented-async-def
> new file mode 100644
> index 000000000..f5d03258a
> --- /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,
> + ]
> ...
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] userdiff: support Python async functions
2019-11-20 3:59 ` Junio C Hamano
@ 2019-11-20 6:48 ` Johannes Sixt
0 siblings, 0 replies; 3+ messages in thread
From: Johannes Sixt @ 2019-11-20 6:48 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Josh Holland, git
Am 20.11.19 um 04:59 schrieb Junio C Hamano:
> Josh Holland <anowlcalledjosh@gmail.com> writes:
>
>> This patch now includes tests for indented declarations, as well as the
>> unindented versions which were present before.
>
> Very much appreciated.
>
> I wondered if something like
>
> diff --git a/t/t4018/python-indented-async-def b/t/t4018/python-indented-async-def
> index f5d03258af..567c1dafcb 100644
> --- a/t/t4018/python-indented-async-def
> +++ b/t/t4018/python-indented-async-def
> @@ -1,3 +1,6 @@
> +async def not_this_one(self):
> + return []
> +
> class Foo:
> async def RIGHT(self, x: int):
> return [
>
> would further help, but if a breakage makes us ignore a start of
> definition that is indented, we would hit "class Foo:" you added
> and notice such a breakage anyway, without additional definition
> before it. So I think what we see in this patch is good.
Good point raised and fine analysis!
This patch is
Acked-by: Johannes Sixt <j6t@kdbg.org>
-- Hannes
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-11-20 6:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-19 15:08 [PATCH v2] userdiff: support Python async functions Josh Holland
2019-11-20 3:59 ` Junio C Hamano
2019-11-20 6:48 ` Johannes Sixt
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).