简体   繁体   中英

PyCharm type hinting weirdness

  • PyCharm version 4.5.4

  • Using Python 3.4.3

For some reason I'm seeing this warning in PyCharm, it seems odd.

Expected 'collections.Iterable', got 'range[int]' instead

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.

for _ in range(x):

To me this seems like literally the most idiomatic for loop you can write.

在此输入图像描述

Given your report, this appears to be a bug in PyCharm. A range object is an iterable, and an Iterable. In 3.4.3:

>>> import collections
>>> x = 3
>>> isinstance(range(x), collections.Iterable)
True

Try reporting the issue to PyCharm people.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM