PyCharm版本4.5.4
使用Python 3.4.3
出于某种原因,我在PyCharm中看到了这个警告,看起来很奇怪。
预期' collections.Iterable',得到'范围[int]'代替
此检查检测函数调用表达式中的类型错误。 由于动态调度和鸭子打字,这是有限的 但有用的案件数量。函数参数的类型可以是 在docstrings或Python 3函数注释中指定。
for _ in range(x):
对我而言,这似乎是你可以写的最惯用的for loop。
答案 0 :(得分:10)
鉴于您的报告,这似乎是PyCharm中的一个错误。范围对象是可迭代的,是Iterable。在3.4.3中:
>>> import collections
>>> x = 3
>>> isinstance(range(x), collections.Iterable)
True
尝试向PyCharm人报告此问题。