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.
Not enforced at runtime The Python runtime does not enforce function and variable type annotations. They can be used by third party tools such as type checkers, IDEs, linters, etc.
Type hinting in PyCharm Last modified: 19 September 2022. PyCharm provides various means to assist inspecting and checking the types of the objects in your script. PyCharm supports type hinting in function annotations and type comments using the typing module and the format defined by PEP 484.
Here's how you can add type hints to our function: Add a colon and a data type after each function parameter. Add an arrow ( -> ) and a data type after the function to specify the return data type.
Type hinting is a formal solution to statically indicate the type of a value within your Python code. It was specified in PEP 484 and introduced in Python 3.5. Here's an example of adding type information to a function.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With