Coder Social home page Coder Social logo

Comments (3)

sobolevn avatar sobolevn commented on July 17, 2024

Hi! Thanks for the issue.

However, based on searching on StackOverflow "'int' object is not iterable", the majority of issues fall into the first situation.

I think we cannot make this assumption blindly.

In many cases range(some_int) might not be a proper solution:

  • You might want to use a different name, when some_int is just a typo
  • range might be redefined to something else in this namespace
  • What if some_int is 0 or negative?
>>> list(range(0))
[]
>>> list(range(-1))
[]
  • What if you want some a bit different range? Like range(1, some_int) or range(some_int + 1)?

I would like not to recommend range in the general case.

Maybe start with a discussion on https://discuss.python.org ?

from cpython.

gaogaotiantian avatar gaogaotiantian commented on July 17, 2024

I agree with @sobolevn , this is a change that might introduce a lot of false positive. I agree that may new users probably have had the issue you mentioned, but your solution is too broad.

For example any(1) would create the exact same error message, and converting that to range() is obviously not reasonable. There are just too many cases where an integer could be accidentally used as an iterable and it's not safe to assume the case is when it's being used in a for loop.

Also, your fix checks the exception string for such case, which would also be a bit hacky.

Overall I believe this change has a too large unwanted impact, and I also agree that this should be discussed on dpo first.

from cpython.

terryjreedy avatar terryjreedy commented on July 17, 2024

Add fix hints to exception messages, as here;

>>> mylist = [1,2]
>>> for i in mylis: pass
...
NameError: name 'mylis' is not defined. Did you mean: 'mylist'?

was started just a few versions ago. I agree with others that proposal/patch as is is too broad.
@pablogsal Is restricting hint to where relevant possible?

from cpython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.