Compare commits
4 Commits
95831d5190
...
dingshuo-p
| Author | SHA1 | Date | |
|---|---|---|---|
| b5102b6835 | |||
| 77fd09e6d2 | |||
|
|
91c16cbc88 | ||
|
|
c8c0ef1620 |
@@ -31,9 +31,39 @@ def long_line():
|
|||||||
|
|
||||||
|
|
||||||
# 缺陷9: 缺少空格
|
# 缺陷9: 缺少空格
|
||||||
def missing_spaces():
|
# def missing_spaces():
|
||||||
"""缺少必要空格"""
|
# """缺少必要空格"""
|
||||||
x=1+2
|
# x=1+2
|
||||||
y=3*4
|
# y=3*99
|
||||||
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