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

List:       python-ideas
Subject:    [Python-ideas] Re: PEP8 mandatory-is rule
From:       Todd <toddrjen () gmail ! com>
Date:       2021-09-01 17:22:53
Message-ID: CAFpSVp+xW30w6+eiOt==tp-LqXkEQY2UnLWdgdBumpZChNtZiQ () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


On Wed, Sep 1, 2021, 03:18 Steven D'Aprano <steve@pearwood.info> wrote:

> On Tue, Aug 31, 2021 at 06:18:15PM -0400, Todd wrote:
>
> > You insist that both approaches should be treated as equally valid. But
> > they simply aren't. In the real world, where people are trying to do
> almost
> > anything useful with python, approach 2 is too dangerous to rely on.
>
> In fairness to Nick, he is not talking about the real world. Nick is
> talking about the hot-house environment of *education*, where fragile
> newbies are generally protected from real world issues.
>

First, I address this later in my post. Using "== None" is a bad habit,
there is simply no good reason to do it and lots of reasons not to, so
students just shouldn't get in the habit of doing it in the first place.

Second, in the post I was responding to Nick was explicitly suggesting "==
None" be treated as an equally-acceptable approach in general.

And let's not exaggerate the issue either by using emotive words like
> "dangerous". Outside of numpy arrays and pandas dataframes, I think it
> is highly unlikely that anyone in the real world will come across cases
> where `x == None` will cause your program to silently do the wrong thing
> in a way that can't be solved by telling them "well don't do that then".
>
> In almost all cases, the test we are looking at is used to decide
> whether or not to replace a parameter with a mutable default. So in
> practical terms, the worst thing that will happen is that the caller
> gets the default when they didn't want it.
>

Others in this thread have looked into this and there are a wide variety of
other types that will suffer.

More generally anything that raises an exception when given an invalid
equality test, an extremely common idiom, will be fundamentally broken by
this.  It will be impossible to use them as arguments at all where "==
None" is used, even in cases where they would otherwise work perfectly
fine.  Trying to do so will raise an exception.

[Attachment #5 (text/html)]

<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On \
Wed, Sep 1, 2021, 03:18 Steven D&#39;Aprano &lt;<a \
href="mailto:steve@pearwood.info">steve@pearwood.info</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 \
.8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue, Aug 31, 2021 at 06:18:15PM \
-0400, Todd wrote:<br> <br>
&gt; You insist that both approaches should be treated as equally valid. But<br>
&gt; they simply aren&#39;t. In the real world, where people are trying to do \
almost<br> &gt; anything useful with python, approach 2 is too dangerous to rely \
on.<br> <br>
In fairness to Nick, he is not talking about the real world. Nick is <br>
talking about the hot-house environment of *education*, where fragile <br>
newbies are generally protected from real world \
issues.<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto"><div \
dir="auto">First, I address this later in my post. Using &quot;== None&quot; is a bad \
habit, there is simply no good reason to do it and lots of reasons not to, so \
students just shouldn&#39;t get in the habit of doing it in the first \
place.</div><div dir="auto"><br></div><div dir="auto">Second, in the post I was \
responding to Nick was explicitly suggesting &quot;== None" be treated as an \
equally-acceptable approach in general.</div></div><div dir="auto"><br></div><div \
dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 \
0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> And let&#39;s not exaggerate the \
issue either by using emotive words like <br> &quot;dangerous&quot;. Outside of numpy \
arrays and pandas dataframes, I think it <br> is highly unlikely that anyone in the \
real world will come across cases <br> where `x == None` will cause your program to \
silently do the wrong thing <br> in a way that can&#39;t be solved by telling them \
&quot;well don&#39;t do that then&quot;.<br> <br>
In almost all cases, the test we are looking at is used to decide <br>
whether or not to replace a parameter with a mutable default. So in <br>
practical terms, the worst thing that will happen is that the caller <br>
gets the default when they didn&#39;t want it.<br></blockquote></div></div><div \
dir="auto"><div dir="auto" style="font-family:sans-serif"><div \
dir="auto"><br></div></div><div dir="auto" style="font-family:sans-serif">Others in \
this thread have looked into this and there are a wide variety of other types that \
will suffer.  </div><div dir="auto" style="font-family:sans-serif"><br></div><div \
dir="auto" style="font-family:sans-serif">More generally anything that raises an \
exception when given an invalid equality test, an extremely common idiom, will be \
fundamentally broken by this.   It will be impossible to use them as arguments at all \
where &quot;== None&quot; is used, even in cases where they would otherwise work \
perfectly fine.   Trying to do so will raise an exception.</div></div></div>



_______________________________________________
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/6BR7JLNVVTS5OZ3SZGF3N4GNQODPHE2A/
 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