[issue47202] Feature request: Throw an error when making impossible evaluation against an empty list

2022-04-02 Thread Eric V. Smith


Eric V. Smith  added the comment:

As Jelle says, this can't be a runtime Exception.

At best mypy or a linter could make iterating over an known empty list (like a 
literal []) a warning, not an error as suggested by the OP. I sometimes 
"comment out" loops by doing something like:

for i in []: # long_list_returning_function():
# lots of code here

I do this just to avoid re-indenting everything if I want to skip the loop 
during development.

--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47202] Feature request: Throw an error when making impossible evaluation against an empty list

2022-04-02 Thread Luminair


Luminair  added the comment:

Thank you for the quick response Jelle! I do like mypy, and I will file this 
with them. Good luck with the migration to GitHub :)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47202] Feature request: Throw an error when making impossible evaluation against an empty list

2022-04-02 Thread Jelle Zijlstra


Jelle Zijlstra  added the comment:

This sort of thing would be better caught by a linter or type checker. For 
example, mypy with the `--warn-unreachable` option will flag the `while None:` 
example.

Iterating over an empty list will not currently be caught by mypy, but it's 
common in real code to iterate over a list that may be empty, so it would be a 
major compatibility break for Python to error when iterating over an empty list.

--
nosy: +JelleZijlstra
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue47202] Feature request: Throw an error when making impossible evaluation against an empty list

2022-04-02 Thread Luminair


New submission from Luminair :

Below are four examples of impossible code that operates on nothing. The latter 
two continue silently, throwing no errors. I saw a bug sneak by because of 
this. I wonder if it is within the scope of Python's design to throw Exceptions 
in these situations? 

x = 

for x in : print("This code is never reached")

while(None): print("This code is never reached")

emptylist = []
for x in emptylist:
if emptylist[x] == "This code is never reached":
print("This code is never reached")
else: print("This code is never reached")

--
components: Parser
messages: 416559
nosy: Luminair, lys.nikolaou, pablogsal
priority: normal
severity: normal
status: open
title: Feature request: Throw an error when making impossible evaluation 
against an empty list
type: enhancement
versions: Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com