[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-ideas
Subject:    [Python-ideas] Should bare logical comparisons raise a warning?
From:       ehmatthes () gmail ! com
Date:       2021-11-24 19:15:58
Message-ID: 163778135845.12996.15026304166468050872 () mail ! python ! org
[Download RAW message or body]

Hi everyone,

I've been really impressed by the recent improvements to error messages in Python \
3.10. The specific suggestions in some error messages are going to save countless \
hours of people's time. The benefits for beginners are fairly obvious. But even for \
experienced programmers, the difference between seeing a missing colon in an error \
message and just adding it where it should have been vs spending 30 seconds or a \
minute figuring out what's missing at the start of a loop adds up.

One common error that I haven't seen discussed is bare logical comparisons. They're \
syntactically legal so they don't raise errors, but I have never seen a real-world \
use case for one. Here's the simplest example I can come up with:

name = 'eric'
print(name)

name == 'ever'
print(name)

We want to assign a new value to an existing variable, but we accidentally type a \
second equals sign. The output here makes the mistake fairly obvious, but in longer \
programs it can take a while to spot this issue.

I know there are some editors and linters that flag this. Is there any reason not to \
raise a warning or even an error at the language level? Is there any reason to use a \
bare logical comparison in real-world code? \
_______________________________________________ Python-ideas mailing list -- \
python-ideas@python.org To unsubscribe send an email to python-ideas-leave@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/4QVUWND6FFDWCD3DL3BR3763EQRAAI5D/
 Code of Conduct: http://python.org/psf/codeofconduct/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic