def foo(left, top, right, bottom):
"function for test"
width = right - left
hieght = top - botom
print height, width
>>> checkfunc(foo)
variable 'botom' is global
variable 'height' is global
variable 'hieght' is not used
variable 'bottom' is not used
PythonにPerlの-wみたいなのないのかといわれたので作ってみた。
変数に代入されているけども読み出されていないと「not used」と警告される。
グローバル空間からのロードの警告もつけられる(オプショナル、デフォルトTrue)
指定した変数だけ警告を出力する対象から取り除くこともできる。
@deco_check(["set"])
def checkfunc(func,
print_globals = True,
print_not_used = True,
print_func_name = False,
surpress = []):
(以下略)
整理してラボブログに書く。
西尾泰和のブログ @ Cybozu Labs: Pythonでtypoを素早く察知する方法。書いた。