* [PATCH] tests/qapi-schema: Tidy up pylint warnings and advice
@ 2023-10-25 9:29 Markus Armbruster
2023-11-03 3:21 ` John Snow
2023-11-03 5:33 ` Markus Armbruster
0 siblings, 2 replies; 3+ messages in thread
From: Markus Armbruster @ 2023-10-25 9:29 UTC (permalink / raw)
To: qemu-devel; +Cc: michael.roth
Pylint warns:
tests/qapi-schema/test-qapi.py:139:13: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
tests/qapi-schema/test-qapi.py:143:13: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
Add encoding='utf-8'.
Pylint advises:
tests/qapi-schema/test-qapi.py:143:13: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
Silence this by returning the value directly.
Pylint advises:
tests/qapi-schema/test-qapi.py:221:4: R1722: Consider using sys.exit() (consider-using-sys-exit)
tests/qapi-schema/test-qapi.py:226:4: R1722: Consider using sys.exit() (consider-using-sys-exit)
Sure, why not.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
tests/qapi-schema/test-qapi.py | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py
index d58c31f539..14f7b62a44 100755
--- a/tests/qapi-schema/test-qapi.py
+++ b/tests/qapi-schema/test-qapi.py
@@ -136,12 +136,11 @@ def test_frontend(fname):
def open_test_result(dir_name, file_name, update):
mode = 'r+' if update else 'r'
try:
- fp = open(os.path.join(dir_name, file_name), mode)
+ return open(os.path.join(dir_name, file_name), mode, encoding='utf-8')
except FileNotFoundError:
if not update:
raise
- fp = open(os.path.join(dir_name, file_name), 'w+')
- return fp
+ return open(os.path.join(dir_name, file_name), 'w+', encoding='utf-8')
def test_and_diff(test_name, dir_name, update):
@@ -218,9 +217,9 @@ def main(argv):
test_name = os.path.splitext(base_name)[0]
status |= test_and_diff(test_name, dir_name, args.update)
- exit(status)
+ sys.exit(status)
if __name__ == '__main__':
main(sys.argv)
- exit(0)
+ sys.exit(0)
--
2.41.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tests/qapi-schema: Tidy up pylint warnings and advice
2023-10-25 9:29 [PATCH] tests/qapi-schema: Tidy up pylint warnings and advice Markus Armbruster
@ 2023-11-03 3:21 ` John Snow
2023-11-03 5:33 ` Markus Armbruster
1 sibling, 0 replies; 3+ messages in thread
From: John Snow @ 2023-11-03 3:21 UTC (permalink / raw)
To: Markus Armbruster; +Cc: qemu-devel, michael.roth
On Wed, Oct 25, 2023 at 5:36 AM Markus Armbruster <armbru@redhat.com> wrote:
>
> Pylint warns:
>
> tests/qapi-schema/test-qapi.py:139:13: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
> tests/qapi-schema/test-qapi.py:143:13: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
>
> Add encoding='utf-8'.
This one I think actually matters in some cases. Some esoteric cases
where the platform default isn't UTF-8. Might happen on Windows where
it wants to use UTF-16 or UCS-2 or whatever.
>
> Pylint advises:
>
> tests/qapi-schema/test-qapi.py:143:13: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
>
> Silence this by returning the value directly.
Smart!
>
> Pylint advises:
>
> tests/qapi-schema/test-qapi.py:221:4: R1722: Consider using sys.exit() (consider-using-sys-exit)
> tests/qapi-schema/test-qapi.py:226:4: R1722: Consider using sys.exit() (consider-using-sys-exit)
>
> Sure, why not.
I have no idea why this matters, but I habitually use the sys.exit() form ...
https://docs.python.org/3.11/library/constants.html#constants-added-by-the-site-module
Oh, that's weird. Well, Sure, why not.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
> ---
> tests/qapi-schema/test-qapi.py | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py
> index d58c31f539..14f7b62a44 100755
> --- a/tests/qapi-schema/test-qapi.py
> +++ b/tests/qapi-schema/test-qapi.py
> @@ -136,12 +136,11 @@ def test_frontend(fname):
> def open_test_result(dir_name, file_name, update):
> mode = 'r+' if update else 'r'
> try:
> - fp = open(os.path.join(dir_name, file_name), mode)
> + return open(os.path.join(dir_name, file_name), mode, encoding='utf-8')
> except FileNotFoundError:
> if not update:
> raise
> - fp = open(os.path.join(dir_name, file_name), 'w+')
> - return fp
> + return open(os.path.join(dir_name, file_name), 'w+', encoding='utf-8')
>
>
> def test_and_diff(test_name, dir_name, update):
> @@ -218,9 +217,9 @@ def main(argv):
> test_name = os.path.splitext(base_name)[0]
> status |= test_and_diff(test_name, dir_name, args.update)
>
> - exit(status)
> + sys.exit(status)
>
>
> if __name__ == '__main__':
> main(sys.argv)
> - exit(0)
> + sys.exit(0)
> --
> 2.41.0
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tests/qapi-schema: Tidy up pylint warnings and advice
2023-10-25 9:29 [PATCH] tests/qapi-schema: Tidy up pylint warnings and advice Markus Armbruster
2023-11-03 3:21 ` John Snow
@ 2023-11-03 5:33 ` Markus Armbruster
1 sibling, 0 replies; 3+ messages in thread
From: Markus Armbruster @ 2023-11-03 5:33 UTC (permalink / raw)
To: qemu-devel; +Cc: michael.roth, John Snow
Markus Armbruster <armbru@redhat.com> writes:
> Pylint warns:
>
> tests/qapi-schema/test-qapi.py:139:13: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
> tests/qapi-schema/test-qapi.py:143:13: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
>
> Add encoding='utf-8'.
>
> Pylint advises:
>
> tests/qapi-schema/test-qapi.py:143:13: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)
>
> Silence this by returning the value directly.
>
> Pylint advises:
>
> tests/qapi-schema/test-qapi.py:221:4: R1722: Consider using sys.exit() (consider-using-sys-exit)
> tests/qapi-schema/test-qapi.py:226:4: R1722: Consider using sys.exit() (consider-using-sys-exit)
>
> Sure, why not.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
Queued.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-11-03 5:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-25 9:29 [PATCH] tests/qapi-schema: Tidy up pylint warnings and advice Markus Armbruster
2023-11-03 3:21 ` John Snow
2023-11-03 5:33 ` Markus Armbruster
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 NNTP newsgroup(s).