From 178a27ae40334b35f969549bbb7c88f843bb6c8a Mon Sep 17 00:00:00 2001 From: MalanB Date: Fri, 29 Apr 2022 11:26:42 +0530 Subject: [PATCH 1/3] Added bad-format-string, consider-using-sys-exit, global-statement documentation examples Co-authored-by: Onkar Dixit Co-authored-by: Vladyslav Krylasov --- doc/data/messages/b/bad-format-string/bad.py | 1 + doc/data/messages/b/bad-format-string/good.py | 1 + doc/data/messages/b/bad-format-string/related.rst | 2 ++ doc/data/messages/c/consider-using-sys-exit/bad.py | 4 ++++ doc/data/messages/c/consider-using-sys-exit/good.py | 6 ++++++ doc/data/messages/g/global-statement/bad.py | 9 +++++++++ doc/data/messages/g/global-statement/good.py | 8 ++++++++ 7 files changed, 31 insertions(+) create mode 100644 doc/data/messages/b/bad-format-string/bad.py create mode 100644 doc/data/messages/b/bad-format-string/good.py create mode 100644 doc/data/messages/b/bad-format-string/related.rst create mode 100644 doc/data/messages/c/consider-using-sys-exit/bad.py create mode 100644 doc/data/messages/c/consider-using-sys-exit/good.py create mode 100644 doc/data/messages/g/global-statement/bad.py create mode 100644 doc/data/messages/g/global-statement/good.py diff --git a/doc/data/messages/b/bad-format-string/bad.py b/doc/data/messages/b/bad-format-string/bad.py new file mode 100644 index 0000000000..523b8fba8e --- /dev/null +++ b/doc/data/messages/b/bad-format-string/bad.py @@ -0,0 +1 @@ +print('{a[0] + a[1]}'.format(a=[0, 1])) # [bad-format-string] diff --git a/doc/data/messages/b/bad-format-string/good.py b/doc/data/messages/b/bad-format-string/good.py new file mode 100644 index 0000000000..f2d8919b09 --- /dev/null +++ b/doc/data/messages/b/bad-format-string/good.py @@ -0,0 +1 @@ +print('{a[0]} + {a[1]}'.format(a=[0, 1])) diff --git a/doc/data/messages/b/bad-format-string/related.rst b/doc/data/messages/b/bad-format-string/related.rst new file mode 100644 index 0000000000..b6aadf541e --- /dev/null +++ b/doc/data/messages/b/bad-format-string/related.rst @@ -0,0 +1,2 @@ +- `Format String Syntax `_ +- `PyFormat `_ diff --git a/doc/data/messages/c/consider-using-sys-exit/bad.py b/doc/data/messages/c/consider-using-sys-exit/bad.py new file mode 100644 index 0000000000..40947189c9 --- /dev/null +++ b/doc/data/messages/c/consider-using-sys-exit/bad.py @@ -0,0 +1,4 @@ +if __name__ == '__main__': + user = input('Enter user name: ') + print(f'Hello, {user}') + exit(0) # [consider-using-sys-exit] \ No newline at end of file diff --git a/doc/data/messages/c/consider-using-sys-exit/good.py b/doc/data/messages/c/consider-using-sys-exit/good.py new file mode 100644 index 0000000000..e5142dcda8 --- /dev/null +++ b/doc/data/messages/c/consider-using-sys-exit/good.py @@ -0,0 +1,6 @@ +import sys + +if __name__ == '__main__': + user = input('Enter user name: ') + print(f'Hello, {user}') + sys.exit(0) \ No newline at end of file diff --git a/doc/data/messages/g/global-statement/bad.py b/doc/data/messages/g/global-statement/bad.py new file mode 100644 index 0000000000..b46191bc36 --- /dev/null +++ b/doc/data/messages/g/global-statement/bad.py @@ -0,0 +1,9 @@ +var = 1 + +def foo(): + global var # [global-statement] + var = 10 + print(var) + +foo() +print(var) \ No newline at end of file diff --git a/doc/data/messages/g/global-statement/good.py b/doc/data/messages/g/global-statement/good.py new file mode 100644 index 0000000000..419b3fc840 --- /dev/null +++ b/doc/data/messages/g/global-statement/good.py @@ -0,0 +1,8 @@ +var = 1 + +def foo(x): + print(var) + return 10 + +var = foo() +print(var) \ No newline at end of file From 3b4e55d4aa93526d6eba46a714289ebac3f8d374 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 29 Apr 2022 06:04:42 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- doc/data/messages/c/consider-using-sys-exit/bad.py | 2 +- doc/data/messages/c/consider-using-sys-exit/good.py | 2 +- doc/data/messages/g/global-statement/bad.py | 2 +- doc/data/messages/g/global-statement/good.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/data/messages/c/consider-using-sys-exit/bad.py b/doc/data/messages/c/consider-using-sys-exit/bad.py index 40947189c9..8617a2a4ef 100644 --- a/doc/data/messages/c/consider-using-sys-exit/bad.py +++ b/doc/data/messages/c/consider-using-sys-exit/bad.py @@ -1,4 +1,4 @@ if __name__ == '__main__': user = input('Enter user name: ') print(f'Hello, {user}') - exit(0) # [consider-using-sys-exit] \ No newline at end of file + exit(0) # [consider-using-sys-exit] diff --git a/doc/data/messages/c/consider-using-sys-exit/good.py b/doc/data/messages/c/consider-using-sys-exit/good.py index e5142dcda8..0a73ae4aea 100644 --- a/doc/data/messages/c/consider-using-sys-exit/good.py +++ b/doc/data/messages/c/consider-using-sys-exit/good.py @@ -3,4 +3,4 @@ if __name__ == '__main__': user = input('Enter user name: ') print(f'Hello, {user}') - sys.exit(0) \ No newline at end of file + sys.exit(0) diff --git a/doc/data/messages/g/global-statement/bad.py b/doc/data/messages/g/global-statement/bad.py index b46191bc36..bc2cea0966 100644 --- a/doc/data/messages/g/global-statement/bad.py +++ b/doc/data/messages/g/global-statement/bad.py @@ -6,4 +6,4 @@ def foo(): print(var) foo() -print(var) \ No newline at end of file +print(var) diff --git a/doc/data/messages/g/global-statement/good.py b/doc/data/messages/g/global-statement/good.py index 419b3fc840..939bee43ef 100644 --- a/doc/data/messages/g/global-statement/good.py +++ b/doc/data/messages/g/global-statement/good.py @@ -5,4 +5,4 @@ def foo(x): return 10 var = foo() -print(var) \ No newline at end of file +print(var) From 2f5d8c2cd8e58aefd8b5e8340694f2555a8f59e4 Mon Sep 17 00:00:00 2001 From: MalanB Date: Mon, 2 May 2022 20:22:37 +0530 Subject: [PATCH 3/3] Addressed PR #6472 comments for documentation issue #5953 > > Co-authored-by: Onkar Dixit Co-authored-by: Vladyslav Krylasov --- doc/data/messages/c/consider-using-sys-exit/bad.py | 8 ++++---- doc/data/messages/c/consider-using-sys-exit/good.py | 6 +++--- doc/data/messages/g/global-statement/bad.py | 4 +++- doc/data/messages/g/global-statement/good.py | 4 +++- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/doc/data/messages/c/consider-using-sys-exit/bad.py b/doc/data/messages/c/consider-using-sys-exit/bad.py index 8617a2a4ef..1acc22a158 100644 --- a/doc/data/messages/c/consider-using-sys-exit/bad.py +++ b/doc/data/messages/c/consider-using-sys-exit/bad.py @@ -1,4 +1,4 @@ -if __name__ == '__main__': - user = input('Enter user name: ') - print(f'Hello, {user}') - exit(0) # [consider-using-sys-exit] +if __name__ == "__main__": + user = input("Enter user name: ") + print(f"Hello, {user}") + exit(0) # [consider-using-sys-exit] diff --git a/doc/data/messages/c/consider-using-sys-exit/good.py b/doc/data/messages/c/consider-using-sys-exit/good.py index 0a73ae4aea..acacd343a6 100644 --- a/doc/data/messages/c/consider-using-sys-exit/good.py +++ b/doc/data/messages/c/consider-using-sys-exit/good.py @@ -1,6 +1,6 @@ import sys -if __name__ == '__main__': - user = input('Enter user name: ') - print(f'Hello, {user}') +if __name__ == "__main__": + user = input("Enter user name: ") + print(f"Hello, {user}") sys.exit(0) diff --git a/doc/data/messages/g/global-statement/bad.py b/doc/data/messages/g/global-statement/bad.py index bc2cea0966..aca1dabd24 100644 --- a/doc/data/messages/g/global-statement/bad.py +++ b/doc/data/messages/g/global-statement/bad.py @@ -1,9 +1,11 @@ var = 1 + def foo(): - global var # [global-statement] + global var # [global-statement] var = 10 print(var) + foo() print(var) diff --git a/doc/data/messages/g/global-statement/good.py b/doc/data/messages/g/global-statement/good.py index 939bee43ef..34958b5fe1 100644 --- a/doc/data/messages/g/global-statement/good.py +++ b/doc/data/messages/g/global-statement/good.py @@ -1,8 +1,10 @@ var = 1 -def foo(x): + +def foo(): print(var) return 10 + var = foo() print(var)