Message ID | 20181211115607.13774-7-alice.ferrazzi@gmail.com |
---|---|
State | Changes Requested, archived |
Delegated to: | BPF Maintainers |
Headers | show |
Series | selftest/bpf fix PEP8 warnings | expand |
On Tue, 11 Dec 2018 20:56:06 +0900, Alice Ferrazzi wrote: > Signed-off-by: Alice Ferrazzi <alice.ferrazzi@gmail.com> > --- > tools/testing/selftests/bpf/test_offload.py | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py > index 0f9130ebfd2c..b06cc0eea0eb 100755 > --- a/tools/testing/selftests/bpf/test_offload.py > +++ b/tools/testing/selftests/bpf/test_offload.py > @@ -140,7 +140,7 @@ def cmd_result(proc, include_stderr=False, fail=False): > > > def rm(f): > - cmd("rm -f %s" % (f)) > + cmd("rm -f %s" % f) > if f in files: > files.remove(f) > Is this in PEP8, too?
On 12/12/18 19:04, Jakub Kicinski wrote: > On Tue, 11 Dec 2018 20:56:06 +0900, Alice Ferrazzi wrote: >> Signed-off-by: Alice Ferrazzi <alice.ferrazzi@gmail.com> >> --- >> tools/testing/selftests/bpf/test_offload.py | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py >> index 0f9130ebfd2c..b06cc0eea0eb 100755 >> --- a/tools/testing/selftests/bpf/test_offload.py >> +++ b/tools/testing/selftests/bpf/test_offload.py >> @@ -140,7 +140,7 @@ def cmd_result(proc, include_stderr=False, fail=False): >> >> >> def rm(f): >> - cmd("rm -f %s" % (f)) >> + cmd("rm -f %s" % f) >> if f in files: >> files.remove(f) >> > Is this in PEP8, too? I don't know, but it shouldn't be. If f is a sequence type, both the old and new code can break here, throwing a TypeError. It should be cmd("rm -f %s" % (f,)). The presence of the brackets suggests to me that that's what the original author intended. Now, it's unlikely that we'd ever want to pass a list or tuple here, since 'rm' wouldn't understand the result, but the proper way to deal with that is an assertion with a meaningful message, since the TypeError here will have the non-obvious message "not all arguments converted during string formatting". -Ed
On Wed, 12 Dec 2018 21:15:52 +0000, Edward Cree wrote: > On 12/12/18 19:04, Jakub Kicinski wrote: > > On Tue, 11 Dec 2018 20:56:06 +0900, Alice Ferrazzi wrote: > >> Signed-off-by: Alice Ferrazzi <alice.ferrazzi@gmail.com> > >> --- > >> tools/testing/selftests/bpf/test_offload.py | 2 +- > >> 1 file changed, 1 insertion(+), 1 deletion(-) > >> > >> diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py > >> index 0f9130ebfd2c..b06cc0eea0eb 100755 > >> --- a/tools/testing/selftests/bpf/test_offload.py > >> +++ b/tools/testing/selftests/bpf/test_offload.py > >> @@ -140,7 +140,7 @@ def cmd_result(proc, include_stderr=False, fail=False): > >> > >> > >> def rm(f): > >> - cmd("rm -f %s" % (f)) > >> + cmd("rm -f %s" % f) > >> if f in files: > >> files.remove(f) > >> > > Is this in PEP8, too? > I don't know, but it shouldn't be. > If f is a sequence type, both the old and new code can break here, > throwing a TypeError. It should be cmd("rm -f %s" % (f,)). The > presence of the brackets suggests to me that that's what the > original author intended. Agreed, that was my intention, I didn't know about the comma option. > Now, it's unlikely that we'd ever want to pass a list or tuple > here, since 'rm' wouldn't understand the result, but the proper > way to deal with that is an assertion with a meaningful message, > since the TypeError here will have the non-obvious message "not > all arguments converted during string formatting". Interesting, thanks for the analysis!
diff --git a/tools/testing/selftests/bpf/test_offload.py b/tools/testing/selftests/bpf/test_offload.py index 0f9130ebfd2c..b06cc0eea0eb 100755 --- a/tools/testing/selftests/bpf/test_offload.py +++ b/tools/testing/selftests/bpf/test_offload.py @@ -140,7 +140,7 @@ def cmd_result(proc, include_stderr=False, fail=False): def rm(f): - cmd("rm -f %s" % (f)) + cmd("rm -f %s" % f) if f in files: files.remove(f)
Signed-off-by: Alice Ferrazzi <alice.ferrazzi@gmail.com> --- tools/testing/selftests/bpf/test_offload.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)