[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Steven D'Aprano
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,

[Python-ideas] Remove a single warning from the warnings filter list

2021-09-01 Thread Steven D'Aprano
Maybe I'm missing something, but I don't think that there is anyway to remove a warning from the warnings filter list so that it will be shown again. Example: >>> import warnings >>> warnings.warn("something happened") :1: UserWarning: something happened >>> warnings.warn("somet

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Chris Angelico
On Wed, Sep 1, 2021 at 5:19 PM Steven D'Aprano wrote: > Outside of contrived counter-examples, we're not likely to come across > anything trying to mimac None in the real world. But that's not really > why we use `is`, or at least, it's not the only reason. There are a > bunch of reasons, none of

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Marc-Andre Lemburg
On 01.09.2021 10:27, Chris Angelico wrote: > On Wed, Sep 1, 2021 at 5:19 PM Steven D'Aprano wrote: >> Outside of contrived counter-examples, we're not likely to come across >> anything trying to mimac None in the real world. But that's not really >> why we use `is`, or at least, it's not the only

[Python-ideas] Re: Remove a single warning from the warnings filter list

2021-09-01 Thread Zbigniew Jędrzejewski-Szmek
On Wed, Sep 01, 2021 at 05:27:40PM +1000, Steven D'Aprano wrote: > Maybe I'm missing something, but I don't think that there is anyway to > remove a warning from the warnings filter list so that it will be shown > again. > > Example: > > >>> import warnings > >>> warnings.warn("somethin

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Chris Angelico
On Wed, Sep 1, 2021 at 6:55 PM Marc-Andre Lemburg wrote: > BTW: In SQL you have to use "field IS NULL", "field = NULL" returns > NULL, so you're not any smarter than before :-) That's because NULL is kinda like None, kinda like NaN, kinda like "we don't have any data here", and kinda like "we do

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Steven D'Aprano
On Tue, Aug 31, 2021 at 09:49:36AM -0400, Calvin Spealman wrote: > I think the provenance of the "is None" rule comes from before None was a > guaranteed singleton. In older versions of Python, it was *possible* to > instantiate more instances of None. I don't suppose you can show how that works?

[Python-ideas] Re: Remove a single warning from the warnings filter list

2021-09-01 Thread Peter Otten
On 01/09/2021 09:27, Steven D'Aprano wrote: Maybe I'm missing something, but I don't think that there is anyway to remove a warning from the warnings filter list so that it will be shown again. Example: >>> import warnings >>> warnings.warn("something happened") :1: UserWarning:

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Christopher Barker
Can you redefine the name, “None” in ancient Python? -CHB -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython ___ Python-

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread David Mertz, Ph.D.
On Wed, Sep 1, 2021, 11:55 AM Christopher Barker wrote: > Can you redefine the name, “None” in ancient Python? > I didn't show it in my earlier post, but in Python 1.0.1, you an indeed rebind the name None (much as you could True/False until 2.4 or something... I probably have the version wrong

[Python-ideas] Allow starred expressions to be used as subscripts for nested lookups for getitem and setitem

2021-09-01 Thread Kevin Mills
Given code like this: ``` d = {1: {2: {3: 4}}} print(d[1][2][3]) d[1][2][3] = None print(d) ``` It should be possible to rewrite it using a starred expression, like this: ``` d = {1: {2: {3: 4}}} keys= 1,2,3 print(d[*keys]) d[*keys] = None print(d) ``` Hopefully it's clear from that example wha

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Nick Parlante
Wow Matthias, you are like the pied piper of weird == implementations! I'm glad you were able to put those in the discussion. To check into Python and its standard modules itself ... I can imagine putting together a grep type thing to just dig all the __eq__ out of there and look at them. Like how

[Python-ideas] Re: Allow starred expressions to be used as subscripts for nested lookups for getitem and setitem

2021-09-01 Thread MRAB
On 2021-09-01 17:41, Kevin Mills wrote: Given code like this: ``` d = {1: {2: {3: 4}}} print(d[1][2][3]) d[1][2][3] = None print(d) ``` It should be possible to rewrite it using a starred expression, like this: ``` d = {1: {2: {3: 4}}} keys= 1,2,3 print(d[*keys]) d[*keys] = None print(d) ```

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Todd
On Wed, Sep 1, 2021, 03:18 Steven D'Aprano 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

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Nick Parlante
> > 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. Let me unpack this just a teeny bit. We don't need to think of the students as fragile. Think

[Python-ideas] Re: Allow starred expressions to be used as subscripts for nested lookups for getitem and setitem

2021-09-01 Thread Kevin Mills
No, definitely not. d[1,2,3] and d[1][2][3] are not the same thing. The latter is what I am talking about. ___ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mail

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Ricky Teachey
On Wed, Sep 1, 2021 at 1:32 PM Nick Parlante wrote: > 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. > > > Let me unpack this just a teeny bit.

[Python-ideas] Re: Allow starred expressions to be used as subscripts for nested lookups for getitem and setitem

2021-09-01 Thread David Mertz, Ph.D.
On Wed, Sep 1, 2021 at 12:45 PM Kevin Mills wrote: > d = {1: {2: {3: 4}}} > keys= 1,2,3 > print(d[*keys]) # Meaning: d[1][2][3] > d[*keys] = None > print(d) This is a bad idea for a couple reasons. One reason MRAB points to. The `*keys` syntax is more-or-less equivalent to "substitute a tupl

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Nick Parlante
Hi Ricky, A couple people have said this but I'll ask again because I am curious: > would it be possible to delay introduction of None entirely until it's time > to introduce is? > This maybe comes down to course tactics. I happen to like doing algorithms with data arranged in 2d from the start -

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Nick Parlante
Sorry, replying to myself here, to complete the story here. Or put another way, None is a pretty core Python topic, so there's no sense in dancing around it too much. Really "is" is the problem. I'd rather get into the details of "is" later in the course. So I think two approaches are plausible h

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Christopher Barker
> 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. Sure, but PEP8 is about the real world. Which is why I suggested that Nick might want to create

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread David Mertz, Ph.D.
Nick. I think you should realize that I—and a number of the other people who dislike your elliding the difference between equality and identity—also teach beginning programmers. > 1. You could use "is", and say "It's most proper to use "is" when > comparing to certain values, including None whic

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Christopher Barker
On Wed, Sep 1, 2021 at 12:22 PM Nick Parlante wrote: > Or put another way, None is a pretty core Python topic, so there's no > sense in dancing around it too much. Really "is" is the problem. > Indeed, that's quite true. However, while students will see None very early on in their Python experi

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Brendan Barnwell
On 2021-09-01 10:28, Nick Parlante wrote: Now for Python, == vs. is nothing like that bad. Both == and is are sensible, necessary parts of the language, I would just prefer to talk about == earlier and is later. Of the two, == is the no-brainer one when the students just have ints and strings, an

[Python-ideas] Re: Remove a single warning from the warnings filter list

2021-09-01 Thread Steven D'Aprano
On Wed, Sep 01, 2021 at 03:40:37PM +0200, Peter Otten wrote: > Instead of removing it you might add a filter to get a similar effect: [...] > >>> warnings.filterwarnings("always", "woof!") Unfortunately that's too aggressive. In my use-case, `bark` will be called many, many times in a loop, an

[Python-ideas] Re: Remove a single warning from the warnings filter list

2021-09-01 Thread Chris Angelico
On Wed, Sep 1, 2021 at 6:58 PM Zbigniew Jędrzejewski-Szmek wrote: > > On Wed, Sep 01, 2021 at 05:27:40PM +1000, Steven D'Aprano wrote: > > Maybe I'm missing something, but I don't think that there is anyway to > > remove a warning from the warnings filter list so that it will be shown > > again. >

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Steven D'Aprano
On Wed, Sep 01, 2021 at 12:07:52PM -0400, David Mertz, Ph.D. wrote: > On Wed, Sep 1, 2021, 11:55 AM Christopher Barker > wrote: > > > Can you redefine the name, “None” in ancient Python? > > > > I didn't show it in my earlier post, but in Python 1.0.1, you an indeed > rebind the name None (much

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Steven D'Aprano
On Wed, Sep 01, 2021 at 02:33:20PM -0700, Brendan Barnwell wrote: > There is nothing wrong, in my view, with a teaching approach that > tells people to do a thing one way and then later tells them to move on > to > a different way. This! +1 https://en.wikipedia.org/wiki/Lie-to-chi

[Python-ideas] Re: PEP8 mandatory-is rule

2021-09-01 Thread Steven D'Aprano
On Tue, Aug 31, 2021 at 05:17:35PM -0700, Matthias Bussonnier wrote: > Basically anything that implements __eq__ and assumes it will be > compared only against things that are of the same type will not be > happy to be compared with None using ==. I agree with Oscar that the various objects you l