测试的扫描文件 #20
@@ -36,4 +36,34 @@ def missing_spaces():
|
|||||||
x=1+2
|
x=1+2
|
||||||
y=3*4
|
y=3*4
|
||||||
if x==1:
|
if x==1:
|
||||||
print(x)
|
print(x)
|
||||||
|
|
||||||
|
|
||||||
|
# 缺陷1: 未使用的导入
|
||||||
|
import unused_module # 未使用
|
||||||
|
import collections as col # 使用了 col 但 flake8 可能检测
|
||||||
|
|
||||||
|
|
||||||
|
# 缺陷2: 未使用的变量
|
||||||
|
def unused_variable_demo():
|
||||||
|
"""演示未使用的变量"""
|
||||||
|
result = calculate() # result 未被使用
|
||||||
|
print("Function executed")
|
||||||
|
|
||||||
|
|
||||||
|
def calculate():
|
||||||
|
"""计算并返回结果"""
|
||||||
|
return 42
|
||||||
|
|
||||||
|
|
||||||
|
# 缺陷3: 未定义的变量
|
||||||
|
def undefined_variable_demo():
|
||||||
|
"""演示未定义的变量"""
|
||||||
|
print(undefined_var) # undefined_var 未定义
|
||||||
|
|
||||||
|
|
||||||
|
# 缺陷4: 变量在定义前使用
|
||||||
|
def use_before_define():
|
||||||
|
"""在定义前使用变量"""
|
||||||
|
print(before_var) # before_var 在下面才定义
|
||||||
|
before_var = 100
|
||||||
|
|||||||
Reference in New Issue
Block a user