Re: [Python-ideas] PEP: Dict addition and subtraction
Ka-Ping Yee writes: > On Wed, Mar 6, 2019 at 4:01 PM Chris Angelico wrote: > > But adding dictionaries is fundamentally *useful*. It is expressive. > > It is useful. It's just that + is the wrong name. First, let me say that I prefer ?!'s position here, so my bias is made apparent. I'm also aware that I have biases so I'm sympathetic to those who take a different position. Rather than say it's "wrong", let me instead point out that I think it's pragmatically troublesome to use "+". I can think of at least four interpretations of "d1 + d2" 1. update 2. multiset (~= Collections.Counter addition) 3. addition of functions into the same vector space (actually, a semigroup will do ;-), and this is the implementation of Collections.Counter 4. "fiberwise" set addition (ie, of functions into relations) and I'm very jet-lagged so I may be missing some. There's also the fact that the operations denoted by "|" and "||" are often implemented as "short-circuiting", and therefore not commutative, while "+" usually is (and that's reinforced for mathematicians who are trained to think of "+" as the operator for Abelian groups, while "*" is a (possibly) non-commutative operator. I know commutativity of "+" has been mentioned before, but the non-commutativity of "|" -- and so unsuitability for many kinds of dict combination -- hasn't been emphasized before IIRC. Since "|" (especially "|=") *is* suitable for "update", I think we should reserve "+" for some future commutative extension. In the spirit of full disclosure: Of these, 2 is already implemented and widely used, so we don't need to use dict.__add__ for that. I've never seen 4 in the mathematical literature (union of relations is not the same thing). 3, however, is very common both for mappings with small domain and sparse representation of mappings with a default value (possibly computed then cached), and "|" is not suitable for expressing that sort of addition (I'm willing to say it's "wrong" :-). Steve ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] PEP: Dict addition and subtraction
Ka-Ping Yee writes: > On Wed, Mar 6, 2019 at 4:01 PM Chris Angelico wrote: > > But adding dictionaries is fundamentally *useful*. It is expressive. > > It is useful. It's just that + is the wrong name. First, let me say that I prefer ?!'s position here, so my bias is made apparent. I'm also aware that I have biases so I'm sympathetic to those who take a different position. Rather than say it's "wrong", let me instead point out that I think it's pragmatically troublesome to use "+". I can think of at least four interpretations of "d1 + d2" 1. update 2. multiset (~= Collections.Counter addition) 3. addition of functions into the same vector space (actually, a semigroup will do ;-), and this is the implementation of Collections.Counter 4. "fiberwise" addition (ie, assembling functions into relations) and I'm very jet-lagged so I may be missing some. Since "|" (especially "|=") *is* suitable for "update", I think we should reserve "+" for some alternative future commutative extension, of which there are several possible (all of 2, 3, 4 are commutative). Again in the spirit of full disclosure, of those above, 2 is already implemented and widely used, so we don't need to use "+" for that. I've never seen 4 except in the mathematical literature (union of relations is not the same thing). 3, however, is very common both for mappings with small domain and sparse representation of mappings with a default value (possibly computed then cached), and "|" is not suitable for expressing that sort of addition (I'm willing to say it's "wrong" :-). There's also the fact that the operations denoted by "|" and "||" are often implemented as "short-circuiting", and therefore not commutative, while "+" usually is (and that's reinforced for mathematicians who are trained to think of "+" as the operator for Abelian groups, while "*" is a (possibly) non-commutative operator. I know commutativity of "+" has been mentioned before, but the non-commutativity of "|" -- and so unsuitability for many kinds of dict combination -- hasn't been emphasized before IIRC. Steve ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] PEP: Dict addition and subtraction
Now, this belongs as a separate PEP, and I probably will write one, but I propose: d1 << d2 makes a copy of d1 and merges d2 into it, and when the keys conflict, d2 takes priority. (Works like copy/update.) d1 + d2 makes a new dictionary, taking keys from d1 and d2. If d1 and d2 have a different value for same key, a KeyError is thrown. ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] Make Python 2.7’s online docs optionally redirect to Python 3 online docs
On Fri, Mar 8, 2019 at 10:48 AM Steven D'Aprano wrote: > > /2/ followed by /3.1.5/. No /3/ on first page, so no option to > > influence better placement of /3/. > > You could click through to the second page of search results :-) Obligatory XKCD: https://xkcd.com/1334/ It's unclear whether clicking a link on the second page actually trains the search engine, though. Clicks from the first page are (a) easier to track, and (b) more likely to be useful signals from a user, than clicks from subsequent pages are. But then, we have no real information about what DOES train the search engine, so take it all with a grain of salt. ChrisA ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] Make Python 2.7’s online docs optionally redirect to Python 3 online docs
On Thu, Mar 07, 2019 at 05:53:58PM -0500, Terry Reedy wrote: > On 3/7/2019 8:56 AM, Steven D'Aprano wrote: [...] > >I've found that the search engines are getting better at linking to the > >more recent docs. For example, all of these: > >give me Python 3 first and Python 2 second. [...] > I get /2/ before /3/ Sorry, I forgot to say "Your mileage may vary." Google is well-known for tracking users (even if they aren't logged into a google account at the time) and filtering their search results. As far as I know, only DuckDuckGo promises that all users will see unfiltered results, with everyone seeing the same results from identical searches. So it is quite likely that any other search engine may give different results for identical search terms, according to who you are, whether you are signed into a google account, the country you or your ISP is based in, and the kinds of links you have followed in the past. Not just clicked search links -- Google in particular has an extensive web of tracking bugs throughout the WWW, so they can track you even when you aren't logged in. (Again, YMMV -- those taking active countermeasures may avoid some tracking, and I understand that in the EU Google has legal restrictions on what they collect and what they do with it.) [...] > /2/ followed by /3.1.5/. No /3/ on first page, so no option to > influence better placement of /3/. You could click through to the second page of search results :-) -- Steven ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] Make Python 2.7’s online docs optionally redirect to Python 3 online docs
Steven D'Aprano wrote: I've found that the search engines are getting better at linking to the more recent docs. Likely this is simply due to the fact that Python 3 is being used more than it was, so more of its doc pages are getting linked to. If that's true, then thing should continue to improve over time. -- Greg ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] Make Python 2.7’s online docs optionally redirect to Python 3 online docs
On 3/7/2019 8:56 AM, Steven D'Aprano wrote: On Thu, Mar 07, 2019 at 08:10:20AM -0500, James Lu wrote: Rationale: When I use a search engine to google a Python question, I frequently get a link to a page of the Python 2.7 documentation that shows before the Python 3 documentation link. This is annoying and slows down my programming. Please see https://bugs.python.org/issue35435 and related links from that issue. I've found that the search engines are getting better at linking to the more recent docs. For example, all of these: give me Python 3 first and Python 2 second. https://duckduckgo.com/?q=python+docs+random https://search.yahoo.com/yhs/search?p=python+docs+itertools https://www.bing.com/search?q=python+docs+netrc https://www.startpage.com/do/search?q=python+docs+array Ditto for me: /3/ before /2/. https://www.dogpile.com/serp?q=python+docs+shutil I get /2/ before /3/ Even the comparatively obscure "sndhdr" module gets Python 3 first: https://www.google.com/search?q=python+docs+sndhdr Ditto, but no /2/ on first page. However these gives Python 2 first: https://www.startpage.com/do/search?q=python+docs+netrc /2/ followed by /3.1.5/. No /3/ on first page, so no option to influence better placement of /3/. https://www.dogpile.com/serp?q=python+docs+fileinput I get /3/ before /2/. Does order depend on country? (AU versus US) But note that the docs do include a drop down menu to select the version, so it shouldn't be that difficult to swap from old versions to the most recent. (Unless you're looking at *really* old versions like 1.5.) (Or 3.1.5 ;-) -- Terry Jan Reedy ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] Make Python 2.7’s online docs optionally redirect to Python 3 online docs
The way search engines works is “the more it’s clicked, the higher it is” In order to have python3 on top of the results, just hit the Python3 result :) ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] PEP: Dict addition and subtraction
On Wed, Mar 6, 2019 at 4:01 PM Chris Angelico wrote: > On Thu, Mar 7, 2019 at 10:52 AM Josh Rosenberg > wrote: > > > > Allowing dicts to get involved in + means: > > Lots of words that basically say: Stuff wouldn't be perfectly pure. > > But adding dictionaries is fundamentally *useful*. It is expressive. > It is useful. It's just that + is the wrong name. Filtering and subtracting from dictionaries are also useful! Those are operations we do all the time. It would be useful if & and - did these things too—and if we have & and -, it's going to be even more obvious that the merge operator should have been |. Josh Rosenberg wrote: > If we were inventing programming languages in a vacuum, you could say + > can mean "arbitrary combination operator" and it would be fine. But we're > not in a vacuum; every major language that uses + with general purpose > containers uses it to mean element-wise addition or concatenation, not just > "merge". If we were inventing Python from scratch, we could have decided that we always use "+" to combine collections. Sets would combine with + and then it would make sense that dictionaries also combine with + . But that is not Python. Lists combine with + and sets combine with |. Why? Because lists add (put both collections together and keep everything), but sets merge (put both collections together and keep some). So, Python already has a merge operator. The merge operator is "|". For lists, += is shorthand for list.extend(). For sets, |= is shorthand for set.update(). Is dictionary merge more like extend() or more like update()? Python already took a position on that when it was decided to name the dictionary method update(). That ship sailed a long time ago. —Ping ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] Make Python 2.7’s online docs optionally redirect to Python 3 online docs
On Thu, Mar 07, 2019 at 08:10:20AM -0500, James Lu wrote: > Rationale: When I use a search engine to google a Python question, I > frequently get a link to a page of the Python 2.7 documentation that > shows before the Python 3 documentation link. > > This is annoying and slows down my programming. Please see https://bugs.python.org/issue35435 and related links from that issue. I've found that the search engines are getting better at linking to the more recent docs. For example, all of these: https://duckduckgo.com/?q=python+docs+random https://search.yahoo.com/yhs/search?p=python+docs+itertools https://www.bing.com/search?q=python+docs+netrc https://www.startpage.com/do/search?q=python+docs+array https://www.dogpile.com/serp?q=python+docs+shutil give me Python 3 first and Python 2 second. Even the comparatively obscure "sndhdr" module gets Python 3 first: https://www.google.com/search?q=python+docs+sndhdr However these gives Python 2 first: https://www.startpage.com/do/search?q=python+docs+netrc https://www.dogpile.com/serp?q=python+docs+fileinput But note that the docs do include a drop down menu to select the version, so it shouldn't be that difficult to swap from old versions to the most recent. (Unless you're looking at *really* old versions like 1.5.) -- Steven ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] Make Python 2.7’s online docs optionally redirect to Python 3 online docs
On Thu, Mar 7, 2019 at 9:10 AM James Lu wrote: > Rationale: When I use a search engine to google a Python question, I > frequently get a link to a page of the Python 2.7 documentation that shows > before the Python 3 documentation link. > There exists browser extensions that do this: https://addons.mozilla.org/en-US/firefox/addon/py3direct/ https://chrome.google.com/webstore/detail/py3redirect/codfjigcljdnlklcaopdciclmmdandig?hl=en André Roberge > > This is annoying and slows down my programming. > > I propose: That we add a setting to Python’s online documentation that > will optionally given that certain conditions are met, we redirect the user > to the corresponding Python 3 documentation entry. The conditions: > - The Referer header is set to a URL of a major search engine (the Referer > is the URL of the last page that whose link was clicked on to reach the > documentation) > - The user has opted-in to this behavior. > > (Conceptually this should be user script, but for the collective > conscience of all python developers, a doc option would be better. ) > > I understand that some core devs might just have documentation downloaded > and just use that, but a large portion of Python users primarily use > online documentation > > James Lu > ___ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
[Python-ideas] Make Python 2.7’s online docs optionally redirect to Python 3 online docs
Rationale: When I use a search engine to google a Python question, I frequently get a link to a page of the Python 2.7 documentation that shows before the Python 3 documentation link. This is annoying and slows down my programming. I propose: That we add a setting to Python’s online documentation that will optionally given that certain conditions are met, we redirect the user to the corresponding Python 3 documentation entry. The conditions: - The Referer header is set to a URL of a major search engine (the Referer is the URL of the last page that whose link was clicked on to reach the documentation) - The user has opted-in to this behavior. (Conceptually this should be user script, but for the collective conscience of all python developers, a doc option would be better. ) I understand that some core devs might just have documentation downloaded and just use that, but a large portion of Python users primarily use online documentation James Lu ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/