Comments (3)
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
? Likerange(1, some_int)
orrange(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.
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.
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)
- logging.config: configuring root through dictConfig won't update already existing loggers HOT 1
- AttributeError: 'datetime.datetime' object has no attribute 'times' HOT 1
- [CI/CD] allow to skip tests that are know to lack a C (or Python) implementation. HOT 5
- a biit better example in pathlib docs - maybe include example path that involves file in a folder(s)? HOT 1
- Security branches: Consider fixing the documentation or adding a notice banner HOT 1
- New REPL omits local variables when running ./python -i script.py HOT 2
- importlib.metadata test fixtures should prefer test.support fixtures
- Lacking description of how to correctly implement indexing syntax support.
- Rewrite asyncio subprocesses without child watchers
- Unpickling Exceptions with keyword arguments in multiprocessing throws an error HOT 12
- Reference leak in `_contextvars.Context.run()`
- Allow one to use build.bat to skip building test project files entirely. HOT 4
- CANT FIND THE FUCKING DOWNLOAD BUTTON HOT 2
- Typo in the documentation of the `cmd` parameter of `ftplib.FTP.retrbinary()` HOT 1
- ios buildbot failure: `enclose 'sqlite3_create_window_function' in a __builtin_available check to silence this warning` HOT 1
- generator frame type should not be PyObject*[]
- `subprocess.run` docs should recommend copying `os.environ` on Windows HOT 3
- `faulthandler` itself crashes in free-threading build (in `_Py_DumpExtensionModules`)
- Some Runtime Finalization Constraints Are Not Enforced Nor Documented
- asyncio REPL fails to run with TERM=dumb or PYTHON_BASIC_REPL in 3.13.0b2 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cpython.