* [PATCH] scripts/gdb: replace "is 0" by "== 0"
@ 2020-03-20 16:38 Vincent Bernat
2020-03-20 16:47 ` Kieran Bingham
2020-03-20 16:48 ` Stephen Boyd
0 siblings, 2 replies; 4+ messages in thread
From: Vincent Bernat @ 2020-03-20 16:38 UTC (permalink / raw)
To: Jan Kiszka, Kieran Bingham, Stephen Boyd, linux-kernel; +Cc: Vincent Bernat
While for small numbers, using "node is 0" works with CPython, it is
more portable to use "node == 0". Moreover, with Python 3, this
triggers a syntax warning:
SyntaxWarning: "is" with a literal. Did you mean "=="?
Signed-off-by: Vincent Bernat <vincent@bernat.ch>
---
scripts/gdb/linux/rbtree.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/scripts/gdb/linux/rbtree.py b/scripts/gdb/linux/rbtree.py
index 39db889b874c..87d4738984d2 100644
--- a/scripts/gdb/linux/rbtree.py
+++ b/scripts/gdb/linux/rbtree.py
@@ -17,7 +17,7 @@ def rb_first(root):
raise gdb.GdbError("Must be struct rb_root not {}".format(root.type))
node = root['rb_node']
- if node is 0:
+ if node == 0:
return None
while node['rb_left']:
@@ -33,7 +33,7 @@ def rb_last(root):
raise gdb.GdbError("Must be struct rb_root not {}".format(root.type))
node = root['rb_node']
- if node is 0:
+ if node == 0:
return None
while node['rb_right']:
--
2.26.0.rc2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] scripts/gdb: replace "is 0" by "== 0"
2020-03-20 16:38 [PATCH] scripts/gdb: replace "is 0" by "== 0" Vincent Bernat
@ 2020-03-20 16:47 ` Kieran Bingham
2020-03-20 17:05 ` Vincent Bernat
2020-03-20 16:48 ` Stephen Boyd
1 sibling, 1 reply; 4+ messages in thread
From: Kieran Bingham @ 2020-03-20 16:47 UTC (permalink / raw)
To: Vincent Bernat, Jan Kiszka, Stephen Boyd, linux-kernel
Hi Vincent,
On 20/03/2020 16:38, Vincent Bernat wrote:
> While for small numbers, using "node is 0" works with CPython, it is
> more portable to use "node == 0". Moreover, with Python 3, this
> triggers a syntax warning:
Oh, I thought python encouraged the 'is' style.
>
> SyntaxWarning: "is" with a literal. Did you mean "=="?
Of course that means it clearly doesn't in this case...
> Signed-off-by: Vincent Bernat <vincent@bernat.ch>
Change looks acceptable to me given the report, though a potential
alternative below, otherwise
Reviewed-by: Kieran Bingham <kbingham@kernel.org>
> ---
> scripts/gdb/linux/rbtree.py | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/gdb/linux/rbtree.py b/scripts/gdb/linux/rbtree.py
> index 39db889b874c..87d4738984d2 100644
> --- a/scripts/gdb/linux/rbtree.py
> +++ b/scripts/gdb/linux/rbtree.py
> @@ -17,7 +17,7 @@ def rb_first(root):
> raise gdb.GdbError("Must be struct rb_root not {}".format(root.type))
>
> node = root['rb_node']
> - if node is 0:
> + if node == 0:
Given the nature of the statement, would
if not node:
return None
be any more appropriate ?
> return None
>
> while node['rb_left']:
> @@ -33,7 +33,7 @@ def rb_last(root):
> raise gdb.GdbError("Must be struct rb_root not {}".format(root.type))
>
> node = root['rb_node']
> - if node is 0:
> + if node == 0:
> return None
>
> while node['rb_right']:
>
--
--
Kieran
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scripts/gdb: replace "is 0" by "== 0"
2020-03-20 16:38 [PATCH] scripts/gdb: replace "is 0" by "== 0" Vincent Bernat
2020-03-20 16:47 ` Kieran Bingham
@ 2020-03-20 16:48 ` Stephen Boyd
1 sibling, 0 replies; 4+ messages in thread
From: Stephen Boyd @ 2020-03-20 16:48 UTC (permalink / raw)
To: Jan Kiszka, Kieran Bingham, Vincent Bernat, linux-kernel; +Cc: Vincent Bernat
Quoting Vincent Bernat (2020-03-20 09:38:20)
> While for small numbers, using "node is 0" works with CPython, it is
> more portable to use "node == 0". Moreover, with Python 3, this
> triggers a syntax warning:
>
> SyntaxWarning: "is" with a literal. Did you mean "=="?
>
> Signed-off-by: Vincent Bernat <vincent@bernat.ch>
> ---
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scripts/gdb: replace "is 0" by "== 0"
2020-03-20 16:47 ` Kieran Bingham
@ 2020-03-20 17:05 ` Vincent Bernat
0 siblings, 0 replies; 4+ messages in thread
From: Vincent Bernat @ 2020-03-20 17:05 UTC (permalink / raw)
To: Kieran Bingham; +Cc: Jan Kiszka, Stephen Boyd, linux-kernel
❦ 20 mars 2020 16:47 +00, Kieran Bingham:
> Oh, I thought python encouraged the 'is' style.
Usually, only for "None", "False" or "True" (but for the latest, this
doesn't usually make sense).
> Given the nature of the statement, would
>
> if not node:
> return None
>
> be any more appropriate ?
It would be more consistent with the other uses (like the while below
and the ifs even further). However, I don't fully understand this code
(notably the "node = node.address.cast(...)" where node is not defined
yet and node is replaced by the value of "root['rb_node']" just after),
so can't say for sure node cannot be equal to something eveluating to
False in some conditions.
--
Writing is easy; all you do is sit staring at the blank sheet of paper until
drops of blood form on your forehead.
-- Gene Fowler
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-03-20 17:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-20 16:38 [PATCH] scripts/gdb: replace "is 0" by "== 0" Vincent Bernat
2020-03-20 16:47 ` Kieran Bingham
2020-03-20 17:05 ` Vincent Bernat
2020-03-20 16:48 ` Stephen Boyd
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.