【发布时间】:2018-03-28 20:48:26
【问题描述】:
我对 MacBook 上的 Python(3.6) 代码或 PyCharm IDE 有疑问
我用“timeit”写了一个函数来测试其他函数花费的时间
def timeit_func(func_name, num_of_round=1):
print("start" + func_name.__name__ + "()")
str_setup = "from __main__ import " + func_name.__name__
print('%s() spent %f s' % (func_name.__name__,
timeit.timeit(func_name.__name__ + "()",
setup=str_setup,
number=num_of_round)))
print(func_name.__name__ + "() finish")
参数“func_name”只是一个需要测试并且已经定义好的函数。 我用代码调用这个函数
if __name__ == "__main__":
timeit_func(func_name=another_function)
该函数运行良好,但 pycharm 使用此代码“func_name=another_function”显示信息:
Expected type '{__name__}', got '() -> None' instead less... (⌃F1 ⌥T)
This inspection detects type errors in function call expressions. Due to dynamic dispatch and duck typing, this is possible in a limited but useful number of cases. Types of function parameters can be specified in docstrings or in Python 3 function annotations
我在 Google 上搜索了“预期类型 '{name}',得到了 '() -> None”,但没有任何帮助。我是 Python 新手。 我想问一下是什么意思?我怎样才能让这些信息消失?因为现在它被突出显示,让我感到不舒服。
我在Python3.6 byimport time中使用它,这是我在timeit module()(timeit.timeit())的文档中找到的
def timeit(stmt="pass", setup="pass", timer=default_timer, number=default_number, globals=None):
"""Convenience function to create Timer object and call timeit method."""
return Timer(stmt, setup, timer, globals).timeit(number)
【问题讨论】:
-
什么是
timeit.timeit()函数..? -
已知issue 的函数与
{__name__}类型不匹配。
标签: macos python-3.x pycharm