From 6b7383111ba4c70b6d844d56d6c6dddc9a36580a Mon Sep 17 00:00:00 2001 From: xujian Date: Mon, 4 Dec 2023 08:18:30 +0000 Subject: [PATCH 1/7] =?UTF-8?q?update=20=E7=BC=96=E7=A0=81=E8=A7=84?= =?UTF-8?q?=E8=8C=83/openKylin-python=E8=AF=AD=E8=A8=80=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E7=BC=96=E7=A8=8B=E8=A7=84=E8=8C=83.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xujian --- ...\250\347\274\226\347\250\213\350\247\204\350\214\203.md" | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git "a/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" "b/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" index 2d8bc78..ce6754e 100644 --- "a/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" +++ "b/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" @@ -375,4 +375,8 @@ break和continue是非结构化的控制流语句,在循环体外使用会使 ### 正确代码 if narg == 1: print('@Usage: input_filename nelements nintervals') - sys.exit() \ No newline at end of file + sys.exit() + +# 5 表达式 + +# 6 数据结构 -- Gitee From 0f4917a98f9af2db6396ab612967e70610f2fafa Mon Sep 17 00:00:00 2001 From: xujian Date: Mon, 4 Dec 2023 08:22:28 +0000 Subject: [PATCH 2/7] =?UTF-8?q?update=20=E7=BC=96=E7=A0=81=E8=A7=84?= =?UTF-8?q?=E8=8C=83/openKylin-python=E8=AF=AD=E8=A8=80=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E7=BC=96=E7=A8=8B=E8=A7=84=E8=8C=83.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xujian --- ...224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git "a/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" "b/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" index ce6754e..710b955 100644 --- "a/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" +++ "b/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" @@ -56,7 +56,6 @@ name = other_name target = -num # Compliant; intent to assign inverse value of num is clear target += num - # 2 错误和异常 ## 规则2.1 异常应该从Exception类派生(python:S5632) @@ -379,4 +378,4 @@ break和continue是非结构化的控制流语句,在循环体外使用会使 # 5 表达式 -# 6 数据结构 + -- Gitee From 2265be8a6c4177108dc16175216521008426717c Mon Sep 17 00:00:00 2001 From: xujian Date: Mon, 4 Dec 2023 08:24:31 +0000 Subject: [PATCH 3/7] =?UTF-8?q?update=20=E7=BC=96=E7=A0=81=E8=A7=84?= =?UTF-8?q?=E8=8C=83/openKylin-python=E8=AF=AD=E8=A8=80=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E7=BC=96=E7=A8=8B=E8=A7=84=E8=8C=83.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xujian --- ...4\250\347\274\226\347\250\213\350\247\204\350\214\203.md" | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git "a/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" "b/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" index 710b955..5bb45c6 100644 --- "a/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" +++ "b/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" @@ -2,7 +2,7 @@ # 前言 -# 1 基本语法 +# 1 基本语法与表达式 ## 规则1.1 变量、类、函数应该先定义再使用(python:S3827) 变量、类、函数应该先定义再使用,否则会导致程序报错。 @@ -376,6 +376,3 @@ break和continue是非结构化的控制流语句,在循环体外使用会使 print('@Usage: input_filename nelements nintervals') sys.exit() -# 5 表达式 - - -- Gitee From 8fb0c9505694a5d7ad263156a1164e6de7586dd0 Mon Sep 17 00:00:00 2001 From: xujian Date: Mon, 4 Dec 2023 08:25:04 +0000 Subject: [PATCH 4/7] =?UTF-8?q?update=20=E7=BC=96=E7=A0=81=E8=A7=84?= =?UTF-8?q?=E8=8C=83/openKylin-python=E8=AF=AD=E8=A8=80=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E7=BC=96=E7=A8=8B=E8=A7=84=E8=8C=83.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xujian --- ...\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" "b/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" index 5bb45c6..3b678cb 100644 --- "a/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" +++ "b/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" @@ -172,7 +172,7 @@ name = other_name except Exception: logging.exception("Failed") # Ignore all "Exception" subclasses yet allow SystemExit and other important exceptions to pass -# 3 函数参数与返回值 +# 3 参数与返回值 ## 规则3.1 __init__函数不应该有显示返回值(python:S2734) 在python中,__init__函数是一个特殊的方法,用于在创建类的实例时进行初始化操作。它没有显示的返回值,而是隐式的返回新创建的实例对象。 -- Gitee From 77e0a80c77965893c7d754dcb72c10ca4db66f24 Mon Sep 17 00:00:00 2001 From: xujian Date: Mon, 4 Dec 2023 08:38:20 +0000 Subject: [PATCH 5/7] =?UTF-8?q?update=20=E7=BC=96=E7=A0=81=E8=A7=84?= =?UTF-8?q?=E8=8C=83/openKylin-python=E8=AF=AD=E8=A8=80=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E7=BC=96=E7=A8=8B=E8=A7=84=E8=8C=83.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xujian --- ...26\347\250\213\350\247\204\350\214\203.md" | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git "a/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" "b/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" index 3b678cb..4e5ac05 100644 --- "a/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" +++ "b/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" @@ -56,6 +56,25 @@ name = other_name target = -num # Compliant; intent to assign inverse value of num is clear target += num +## 规则1.4 在一个函数中不应该同时使用return和yield(python:S2712) +使用yield的函数被称为生成器,在Python 3.3之前,生成器不能返回值。同样的,使用return的函数也不能使用yield,这样做将导致SyntaxError。因此要么将Python版本升级到>=3.3版本,要么不要在函数中同时使用return和yield。 +### 错误代码 + def adder(n): + num = 0 + while num < n: + yield num + num += 1 + return num #Noncompliant + +### 正确代码 + def adder(n): + num = 0 + while num < n: + yield num + num += 1 +### 参考资料 + + # 2 错误和异常 ## 规则2.1 异常应该从Exception类派生(python:S5632) -- Gitee From e258e837923e98515653156ea07c1f2d5a3c89dc Mon Sep 17 00:00:00 2001 From: xujian Date: Mon, 4 Dec 2023 08:40:02 +0000 Subject: [PATCH 6/7] =?UTF-8?q?update=20=E7=BC=96=E7=A0=81=E8=A7=84?= =?UTF-8?q?=E8=8C=83/openKylin-python=E8=AF=AD=E8=A8=80=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E7=BC=96=E7=A8=8B=E8=A7=84=E8=8C=83.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xujian --- ...\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" "b/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" index 4e5ac05..241ffde 100644 --- "a/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" +++ "b/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" @@ -73,7 +73,7 @@ name = other_name yield num num += 1 ### 参考资料 - +https://docs.python.org/zh-cn/3/reference/expressions.html#yieldexpr # 2 错误和异常 ## 规则2.1 异常应该从Exception类派生(python:S5632) -- Gitee From 1e70580b9763dd726c3f57b235641a59975cb00a Mon Sep 17 00:00:00 2001 From: xujian Date: Mon, 4 Dec 2023 08:41:08 +0000 Subject: [PATCH 7/7] =?UTF-8?q?update=20=E7=BC=96=E7=A0=81=E8=A7=84?= =?UTF-8?q?=E8=8C=83/openKylin-python=E8=AF=AD=E8=A8=80=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E7=BC=96=E7=A8=8B=E8=A7=84=E8=8C=83.md.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xujian --- ...\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" "b/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" index 241ffde..7e4e752 100644 --- "a/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" +++ "b/\347\274\226\347\240\201\350\247\204\350\214\203/openKylin-python\350\257\255\350\250\200\351\200\232\347\224\250\347\274\226\347\250\213\350\247\204\350\214\203.md" @@ -73,7 +73,7 @@ name = other_name yield num num += 1 ### 参考资料 -https://docs.python.org/zh-cn/3/reference/expressions.html#yieldexpr +[python手册-yield表达式](https://docs.python.org/zh-cn/3/reference/expressions.html#yieldexpr) # 2 错误和异常 ## 规则2.1 异常应该从Exception类派生(python:S5632) -- Gitee