PyCharm type hinting weirdness

0 votes

While working with PyCharm, I am getting the following error: 

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):

This is how I have written the for loop. Is there any other solution?

Jul 22, 2019 in Python by ana1504.k
• 7,910 points
3,704 views

1 answer to this question.

0 votes

This looks like 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.

answered Jul 22, 2019 by SDeb
• 13,300 points

Related Questions In Python

0 votes
1 answer

Type checking in Python

Use the type() function with the variable ...READ MORE

answered May 8, 2018 in Python by Nietzsche's daemon
• 4,260 points
501 views
0 votes
1 answer

What are the differences between type() and isinstance()?

To summarize the contents of other (already ...READ MORE

answered Jun 4, 2018 in Python by aryya
• 7,460 points
685 views
0 votes
1 answer

What are the differences between type() and is instance()?

Normally, in Python, you want your code ...READ MORE

answered Aug 6, 2018 in Python by Priyaj
• 58,020 points
639 views
0 votes
1 answer

What's the canonical way to check for type in Python?

To check if o is an instance ...READ MORE

answered Aug 24, 2018 in Python by Priyaj
• 58,020 points
949 views
0 votes
1 answer
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 58,020 points
1,680 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 14, 2018 in Python by Priyaj
• 58,020 points
857 views
0 votes
1 answer

“stub” __objclass__ in a Python class how to implement it?

You want to avoid interfering with this ...READ MORE

answered Sep 27, 2018 in Python by Priyaj
• 58,020 points
2,356 views
0 votes
1 answer

How to get base class type in Python?

Yes, There is an alternative. You can ...READ MORE

answered Feb 8, 2019 in Python by SDeb
• 13,300 points
2,197 views
0 votes
1 answer

python structured/recarray type conversion behaviour

You need to specify a string width, ...READ MORE

answered May 15, 2019 in Python by SDeb
• 13,300 points
494 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP