Re: [Python-ideas] PEP 505: None-aware operators

2018-08-01 Thread Steven D'Aprano
On Wed, Aug 01, 2018 at 11:03:05AM +0100, Jonathan Fine wrote: [...] > After my last post, you wrote > > None.?__str__ > > produces None, even though None has a __str__ attribute. > > This surprises me. But I think it follows from the rules in >

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-02 Thread Steven D'Aprano
On Thu, Aug 02, 2018 at 06:50:47PM +0200, Pål Grønås Drange wrote: > > Reads the same out loud despite being a different operator. > > How are `??`, `.?`, and the others pronounced? Did you read the PEP? It answers that question. https://www.python.org/dev/peps/pep-0505/#reading-expressions

Re: [Python-ideas] With expressions

2018-08-02 Thread Steven D'Aprano
On Thu, Aug 02, 2018 at 03:13:25PM +0200, Robert Vanden Eynde wrote: > This brings the discussion of variable assignement in Expression. Functional > programming community seems to be more interested in python. I'm not sure what you mean there. Your English grammar is just slightly off, enough

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-29 Thread Steven D'Aprano
On Sun, Jul 29, 2018 at 12:49:13PM +1200, Greg Ewing wrote: > Abe Dillon wrote: > >others countering that `person.name ` is not how > >periods are used in natural languages, so using other symbols in > >unintuitive ways is perfectly fine. > > Dots have been used for

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-29 Thread Steven D'Aprano
On Sat, Jul 28, 2018 at 10:56:13PM -0500, Abe Dillon wrote: > > > > Python does not have memory locations. > > > > CPython does, form the documentation on the `id` function: No, that is the same id() function as the id() provided by Jython, and IronPython, and Stackless. Like all Python

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-29 Thread Steven D'Aprano
On Sun, Jul 29, 2018 at 06:32:19AM -0400, David Mertz wrote: > On Sun, Jul 29, 2018, 2:00 AM Steven D'Aprano wrote: > > > Fine. So it takes them an extra day to learn one more operator. Big > > deal. It is commonly believed to take ten years to master a field or > > lan

[Python-ideas] Proposed alternative postfix syntax [was PEP 505: None-aware operators]

2018-07-29 Thread Steven D'Aprano
On Sun, Jul 29, 2018 at 02:12:22AM -0500, Abe Dillon wrote: [I said this] > > Python is very little like natural language. Your earlier idea that > > attribute access spam.eggs is like natural language (in English) because > > its only a few characters different from "spam's eggs" really doesn't

Re: [Python-ideas] Redefining method

2018-07-30 Thread Steven D'Aprano
On Tue, Jul 31, 2018 at 10:10:32AM +1200, Greg Ewing wrote: > Jamesie Pic wrote: > >def o.bar(self): ... > > You could get almost the same effect with > >from functools import partial > >def bar(self, other_args): > ... > >o.bar = partial(bar, o) Why are you using

Re: [Python-ideas] Change repr of collections.OrderedDict to be more dict-like

2018-07-26 Thread Steven D'Aprano
On Thu, Jul 26, 2018 at 06:50:20PM -0400, David Mertz wrote: > I often use doctests to verify APIs and behaviors when I update code. I > know I'm in a minority and most developers slightly disparage doctests. I don't know why you think that "most developers" disparage doctests. Perhaps they're

Re: [Python-ideas] As-do statements/anonymous blocks in python

2018-07-27 Thread Steven D'Aprano
I *think* you are trying to find a syntax for "code blocks" like Ruby has, but I'm not sure. Your examples are a little confusing to me (possibly because you have at least three separate suggestions here, "as" blocks, a mysterious "do" keyword I don't understand, and partial application using %

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Steven D'Aprano
On Wed, Jul 25, 2018 at 11:09:35PM -0400, David Mertz wrote: > Chris Angelica provided a more accurate translation. Do you not see that > the fact that your *second* try at understanding the actual behavior is > still wrong suggest that this operator is a HUGE bug magnet?! Oh what a load of

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Steven D'Aprano
On Thu, Jul 26, 2018 at 01:02:47AM -0400, Amit Green wrote: > 3. The problem is way deeper than simply adding '?.' and other operators. > For real use cases, you also need to say "how far" the an operator can > "spread" -- and this is real hard to solve. Why do you think that is the case? No

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Steven D'Aprano
On Wed, Jul 25, 2018 at 12:12:40PM -0400, Nicholas Chammas wrote: > When something is "explicit", as I understand it, that means it does what > it says on the cover. There is no unstated behavior. The plain meaning of > `v = a?.b` is that it expands to the longer form (`v = a; if a.b ...`), and >

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-25 Thread Steven D'Aprano
On Tue, Jul 24, 2018 at 08:07:36AM -0400, Richard Damon wrote: > The fact that you changed NullCoalesce into Foo to show lack of > explicitness seems a straw-man. I understood Rhodri as making the point that if you don't know what NullCoalesce means or does, it might as well be called Foo.

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread Steven D'Aprano
On Tue, Jul 31, 2018 at 02:14:19PM -0400, David Mertz wrote: > On Tue, Jul 31, 2018, 1:47 PM Steven D'Aprano wrote: > > > Yes it is. Rhodri is correct, although I admit that I hadn't realised > > this point myself until he pointed it out. (That is why until now I've > &g

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-31 Thread Steven D'Aprano
On Mon, Jul 30, 2018 at 12:41:20PM -0500, Abe Dillon wrote: [Rhodri James] > > On 29/07/18 16:12, Abe Dillon wrote: > > > spam?.eggs.cheese.aardvark # why would you ever do this? > > > > If you knew that if you really have something in "spam", your program > > guarantees it will have an "eggs"

Re: [Python-ideas] With expressions

2018-08-03 Thread Steven D'Aprano
On Sat, Aug 04, 2018 at 12:28:40AM +0200, Robert Vanden Eynde wrote: > As the code I showed, being just that: > > filename = ... > lines = ... > parsed_data = ... > > With implementation details? The highest value is there, the alg is clear., > one fetches the filename, one preprocess the

Re: [Python-ideas] With expressions

2018-08-03 Thread Steven D'Aprano
On Fri, Aug 03, 2018 at 12:49:24PM +0200, Robert Vanden Eynde wrote: > Le ven. 3 août 2018 à 03:07, Steven D'Aprano a écrit : > > > On Thu, Aug 02, 2018 at 03:13:25PM +0200, Robert Vanden Eynde wrote: > > > > > This brings the discussion of variable assignement in

Re: [Python-ideas] PEP 505: None-aware operators: operators ?= and ?? and OR

2018-08-03 Thread Steven D'Aprano
On Fri, Aug 03, 2018 at 06:30:25AM -0700, Eric Fahlgren wrote: > After looking at the code a bit more, I agree, we've uncovered a bug in the > stdlib and the null coalescing version actually fixes it. [...] > But! We are not here to talk about bugs in the email package, this > discussion is

Re: [Python-ideas] Revisiting dedicated overloadable boolean operators

2018-08-04 Thread Steven D'Aprano
On Sat, Aug 04, 2018 at 02:04:01PM +, Dan Sommers wrote: > On Sat, 04 Aug 2018 23:13:34 +1000, Steven D'Aprano wrote: > > > There are certainly advantages to using binary operators over named > > functions, and a shortage of good, ASCII punctuation suitable for new > &

Re: [Python-ideas] Syntactic sugar to declare partial functions

2018-08-04 Thread Steven D'Aprano
On Sat, Aug 04, 2018 at 09:03:50AM -0700, Fabrizio Messina wrote: > At the moment we have to load the *partial* function from the *functool* > library, and apply it to an existing function [...] > While partial expose the mechanism excellently its instantiation method is, > at times, not very

Re: [Python-ideas] Revisiting dedicated overloadable boolean operators

2018-08-04 Thread Steven D'Aprano
On Sat, Aug 04, 2018 at 02:40:54PM -0400, Todd wrote: > On Sat, Aug 4, 2018 at 9:13 AM, Steven D'Aprano wrote: > > > On Fri, Aug 03, 2018 at 03:17:42PM -0400, Todd wrote: > > > > > Boolean operators like the sort I am discussing have been a standard part > >

Re: [Python-ideas] Revisiting dedicated overloadable boolean operators

2018-08-04 Thread Steven D'Aprano
On Sat, Aug 04, 2018 at 04:56:56PM +0200, Benedikt Werner wrote: > >I think that before adding more ad hoc binary operators, we ought to > >consider the possibility of custom operators. > > That actually sounds like the most sensible solution so far Thanks :-) Unfortunately there's a flaw, in

Re: [Python-ideas] Revisiting dedicated overloadable boolean operators

2018-08-04 Thread Steven D'Aprano
On Fri, Aug 03, 2018 at 03:17:42PM -0400, Todd wrote: > Boolean operators like the sort I am discussing have been a standard part > of programming languages since forever. In fact, they are the basic > operations on which modern microprocessors are built. > > The fact that Python, strictly

Re: [Python-ideas] Revisiting dedicated overloadable boolean operators

2018-08-04 Thread Steven D'Aprano
On Sat, Aug 04, 2018 at 09:16:35PM -0400, Todd wrote: [Chris said:] > > You say that Python doesn't have them. What aspect of boolean > > operators doesn't Python have? > > > > Python's "and" and "or" don't return "True" or "False" per se, they return > one of the inputs based on their

Re: [Python-ideas] With expressions

2018-08-02 Thread Steven D'Aprano
On Thu, Aug 02, 2018 at 11:35:11AM +0200, Ken Hilton wrote: > Where this would benefit: I think the major use case is `f.read() with > open('file') as f`. [...] > Therefore `f.read() with open('file') as f`, I think, would be much > welcomed as the best way to read a file in an expression.

Re: [Python-ideas] As-do statements/anonymous blocks in python

2018-07-26 Thread Steven D'Aprano
On Thu, Jul 26, 2018 at 02:07:07PM +0200, Michel Desmoulin wrote: > 4 - introducing a new keyword is the hardest thing you can ever ask on > this list. Introducing a new keyword is like falling off a log compared to introducing a new operator. -- Steve

Re: [Python-ideas] Consider adding an iterable option to dataclass

2018-08-10 Thread Steven D'Aprano
On Fri, Aug 10, 2018 at 04:01:59PM -0700, Neil Girdhar wrote: > It would be nice if dataclasses > (https://docs.python.org/3/library/dataclasses.html#dataclasses.dataclass) > had an option to make them a sequence. Do you have a use-case or reason for this other than "it would be nice"? Nice in

Re: [Python-ideas] With expressions

2018-08-04 Thread Steven D'Aprano
On Fri, Aug 03, 2018 at 06:57:40PM -0500, Abe Dillon wrote: > tmp = None > with suppress(AttributeError): > tmp = person.name[0] > initial = tmp > > Then it would solve many of the common use cases for the None-aware > operators proposed in PEP 505 No it would not. The None-aware operators

Re: [Python-ideas] With expressions

2018-08-04 Thread Steven D'Aprano
On Sat, Aug 04, 2018 at 12:40:13AM +0200, Benedikt Werner wrote: > Overall I like the idea of the with-expression as it allows you to make > some common use cases like the open/read example more readable. For some definition of "readable". > It's > clear at first sight that what is actually

Re: [Python-ideas] File format for automatic and manual tests

2018-08-07 Thread Steven D'Aprano
On Wed, Aug 08, 2018 at 12:57:51AM +0300, Victor Porton wrote: > This is an idea of a new PEP. > > I propose to create a portable file format which will list command line > options to run Python scripts with dual purpose: Feel free to create whatever file format you like. There are tens of

Re: [Python-ideas] Make "yield" inside a with statement a SyntaxError

2018-08-08 Thread Steven D'Aprano
On Tue, Aug 07, 2018 at 11:31:35PM -0700, Elazar wrote: > Instead of disallowing code, this is a case for allowing with expressions: Only if you accept Ken's conclusion, that yielding inside a with statement is harmful (I don't). And if you do accept Ken's conclusion, then with-expressions

Re: [Python-ideas] Jump to function as an an alternative to call function

2018-08-15 Thread Steven D'Aprano
On Wed, Aug 15, 2018 at 01:52:27PM -0500, Jacob Solinsky wrote: > -Jumping to a function as opposed to calling a function > > When a function is jumped to, it inherits the variables in the > caller’s local namespace and is free to modify them or add new local > variables, unlike a normal

Re: [Python-ideas] Jump to function as an an alternative to call function

2018-08-15 Thread Steven D'Aprano
On Wed, Aug 15, 2018 at 08:35:35PM -0400, David Mertz wrote: > Goto considered harmful. Fortunately this proposal has nothing to do with goto. Elazar is correct that its a kind of subroutine call, just like an ordinary function call, except the scoping rules are different. And for the record,

Re: [Python-ideas] Jump to function as an an alternative to call function

2018-08-16 Thread Steven D'Aprano
On Wed, Aug 15, 2018 at 09:58:28PM -0400, David Mertz wrote: > When did you last read the Dijkstra paper. It's short and he explains very > well why exactly all the constructs you mention are unlike Goto. Of course I've read it, and no he does not. He only mentions if...else and looping. He

Re: [Python-ideas] Syntactic sugar to declare partial functions

2018-08-13 Thread Steven D'Aprano
think that 3/4 of the world learns English just to write > Python? That's not what I wrote. There's a difference between these two positions: - needing to learn to read English words to use Python; - using Python is the only reason to learn English. I said the first, not the second. >

Re: [Python-ideas] Syntactic sugar to declare partial functions

2018-08-14 Thread Steven D'Aprano
On Mon, Aug 13, 2018 at 07:46:49PM +0200, Stefan Behnel wrote: > Michel Desmoulin schrieb am 09.08.2018 um 18:59: > > I'd rather have functools.partial() to be added as a new method on > > function objects. [...] > > add_2 = add.partial(2) > > Except that this only works for functions, not for

Re: [Python-ideas] Jump to function as an an alternative to call function

2018-08-16 Thread Steven D'Aprano
On Thu, Aug 16, 2018 at 10:31:28AM +0200, Brice Parent wrote: > If I understand well the need (I'm unsure I've had it myself), it would > be easier to be able to import the function in the active context, like > this: > > def foo(a): >     return a + c > > def bar(a, c): >     return foo(a) >

Re: [Python-ideas] Jump to function as an an alternative to call function

2018-08-16 Thread Steven D'Aprano
On Thu, Aug 16, 2018 at 09:34:57AM -0700, Chris Barker wrote: > On Thu, Aug 16, 2018 at 1:28 AM, Steven D'Aprano > wrote: > > > there > > are times where I have really wanted to access the caller's environment, > > not the environment where my function was defined.

Re: [Python-ideas] Revisiting dedicated overloadable boolean operators

2018-08-06 Thread Steven D'Aprano
On Mon, Aug 06, 2018 at 02:44:24PM -0700, Neil Girdhar wrote: > This doesn't work because the logical Boolean operators short circuit in > Python. So you could not even define these operators for the regular > Python types. Todd is not proposing to add dunder methods for the existing "or" and

Re: [Python-ideas] Syntactic sugar to declare partial functions

2018-08-12 Thread Steven D'Aprano
g how few programmers know the term "partial", what I think is "what a great opportunity for them to learn something new!". Or not, of course. For those of us who don't care for functional programming idioms, there's no need to use partial in our own code. > [Steven D'Aprano

Re: [Python-ideas] Syntactic sugar to declare partial functions

2018-08-10 Thread Steven D'Aprano
On Thu, Aug 09, 2018 at 01:32:00PM -0500, Abe Dillon wrote: > I'd like to push for the less jargon-y `func.given()` version if this gains > traction. Not only is it shorter, it's a much more common term with a clear > meaning. It's a clear, *generic* meaning that doesn't have any association

Re: [Python-ideas] Python certification

2018-08-09 Thread Steven D'Aprano
On Thu, Aug 09, 2018 at 06:40:23PM +0100, Jonathan Fine wrote: > Hi Oleg > > You wrote > > >In what way certification programs are related to documentation, > > especially to the tutorial? > > One way is through syllabus. Necessarily, a certification via exam > requires a syllabus (or a

Re: [Python-ideas] Off topic: 'strike a balance' - second language English

2018-08-20 Thread Steven D'Aprano
On Mon, Aug 20, 2018 at 09:07:20AM -0700, Chris Barker via Python-ideas wrote: > (side note -- are all domain-specific technical term "jargon"? Yes. But not all jargon is a domain-specific technical term. https://en.wiktionary.org/wiki/jargon -- Steve

Re: [Python-ideas] Pre-conditions and post-conditions

2018-08-21 Thread Steven D'Aprano
On Tue, Aug 21, 2018 at 09:06:54AM +0200, Marko Ristin-Kaufmann wrote: > Is there any chance to introduce these constructs in the language or is it > too small a feature for such a big change? I don't think contracts is a small feature. I think it is a HUGE feature, but under-appreciated by

Re: [Python-ideas] A simple proposal concerning lambda

2018-08-21 Thread Steven D'Aprano
On Tue, Aug 21, 2018 at 10:27:20PM +0100, Jonathan Fine wrote: > Here is my simple proposal. Enhance Python to allow > > >>> hn = def a, b=2, c=3: a ** b / c Enhancements ought to allow us to write new code that we couldn't do before, or open up new kinds of algorithms that weren't easy or

Re: [Python-ideas] Does jargon make learning more difficult?

2018-08-22 Thread Steven D'Aprano
On Tue, Aug 21, 2018 at 05:45:53PM -0500, Abe Dillon wrote: > Can you explain how far the parser is capable of backtracking? Its an LL(1) parser, if I recall correctly, so if you look at the details of LL(1) parsing, that should answer the question. https://en.wikipedia.org/wiki/LL_parser But

Re: [Python-ideas] Does jargon make learning more difficult?

2018-08-22 Thread Steven D'Aprano
On Tue, Aug 21, 2018 at 01:56:16PM -0500, Abe Dillon wrote: > The revelation that it's a function should come when you read the "by" or > "key". I disagree. The most important fact is that it is a function, not specifically what it does. Consider: widget.register(value[a](x)

Re: [Python-ideas] Does jargon make learning more difficult?

2018-08-23 Thread Steven D'Aprano
On Thu, Aug 23, 2018 at 05:55:13PM +1200, Greg Ewing wrote: > Chris Angelico wrote: > >for those who > >know Greek, it's like calling something an "S-expression", which is > >fairly obviously an abbreviation for something. ("Symbolic > >expression", I think? Someone might correct me there.) > >

Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-23 Thread Steven D'Aprano
Hi Mike, and welcome! On Thu, Aug 23, 2018 at 06:49:48PM +, Mike Barnett wrote: > Python has dropped the GUI ball, at least for beginners (in my opinion) Sadly I think that GUIs is one area where Python has not excelled. > While the Python language is awesomely compact, the GUI code is

Re: [Python-ideas] Unpacking iterables for augmented assignment

2018-08-26 Thread Steven D'Aprano
On Sun, Aug 26, 2018 at 06:19:36PM +0100, Jonathan Fine wrote: > Finally, here's something that surprised me a little bit > > >>> x = [1, 2]; id(x) > 140161160364616 > >>> x += [3, 4]; id(x) > 140161160364616 > >>> x = (1, 2); id(x) > 140161159928520 > >>> x += (3, 4); id(x) > 140161225906440 >

Re: [Python-ideas] Pre-conditions and post-conditions

2018-08-28 Thread Steven D'Aprano
On Tue, Aug 28, 2018 at 07:46:02AM +0200, Marko Ristin-Kaufmann wrote: > Hi, > To clarify the benefits of the contracts, let me give you an example from > our code base: > > @icontract.pre(lambda x: x >= 0) > @icontract.pre(lambda y: y >= 0) > @icontract.pre(lambda width: width >= 0) >

Re: [Python-ideas] Pre-conditions and post-conditions

2018-08-29 Thread Steven D'Aprano
On Wed, Aug 29, 2018 at 05:52:46PM +1200, Greg Ewing wrote: > Wes Turner wrote: > >I'm going to re-write that in a pseudo-Eiffel like syntax: > > Maybe some magic could be done to make this work: > > def __init__(self, img: np.ndarray, x: int, y: int, width: int, > height:

Re: [Python-ideas] Pre-conditions and post-conditions

2018-08-27 Thread Steven D'Aprano
On Mon, Aug 27, 2018 at 09:04:21AM +0200, Jacco van Dorp wrote: > Total noob speaking here, but > > Those contracts are mostly important during development right ? That assumes that production code is free of bugs. Usual practice in the Eiffel world is, I believe, to disable post-

Re: [Python-ideas] Pre-conditions and post-conditions

2018-08-27 Thread Steven D'Aprano
On Mon, Aug 27, 2018 at 09:24:20AM +0100, Ivan Levkivskyi wrote: > TBH, I think one of the main points of design by contract is that contracts > are verified statically. No, that's not correct. Contracts may be verified statically if the compiler is able to do so, but they are considered runtime

Re: [Python-ideas] Pre-conditions and post-conditions

2018-08-27 Thread Steven D'Aprano
On Mon, Aug 27, 2018 at 12:12:22PM +0100, Ivan Levkivskyi wrote: > On Mon, 27 Aug 2018 at 11:39, Steven D'Aprano wrote: > > > On Mon, Aug 27, 2018 at 09:24:20AM +0100, Ivan Levkivskyi wrote: > > > TBH, I think one of the main points of design by contract is that > > c

Re: [Python-ideas] Pre-conditions and post-conditions

2018-08-27 Thread Steven D'Aprano
On Mon, Aug 27, 2018 at 11:01:21AM -0400, Wes Turner wrote: > Runtime checks: data validation & code validation > Compile-time checks: code validation > > What sort of data validation is appropriate for assert statements or > contacts that may be skipped due to trading performance for more risk >

Re: [Python-ideas] Does jargon make learning more difficult?

2018-08-22 Thread Steven D'Aprano
On Thu, Aug 23, 2018 at 03:12:30PM +1200, Greg Ewing wrote: > Abe Dillon wrote: > >They still find it's better to use a red break > >light symbol with the aim of clearly communicating to non-experts. > > The handbrake warning light on my dashboard has a symbol > that represents a brake drum and

Re: [Python-ideas] REPL features

2018-08-22 Thread Steven D'Aprano
On Wed, Aug 22, 2018 at 06:01:05PM -0400, Wes Turner wrote: > %edit -p > > > Bring up an editor and execute the resulting code. https://code.activestate.com/recipes/578926-call-out-to-an-external-editor/ -- Steve ___ Python-ideas mailing list

Re: [Python-ideas] Does jargon make learning more difficult?

2018-08-22 Thread Steven D'Aprano
Michael makes some reasonable points, but I think the very premise of this thread is putting the cart before the horse. As educators, if we fail to teach the technical language of a field to our students, we are failing to prepare those students to enter that field. Technical jargon is the

Re: [Python-ideas] Does jargon make learning more difficult?

2018-08-22 Thread Steven D'Aprano
On Wed, Aug 22, 2018 at 12:11:40PM -0500, Abe Dillon wrote: > [Steven D'Aprano] > > > > The revelation that it's a function should come when you read the "by" or > > > "key". > > I disagree. The most important fact is that it is a function, not &

Re: [Python-ideas] A simple proposal concerning lambda

2018-08-22 Thread Steven D'Aprano
On Wed, Aug 22, 2018 at 04:58:17PM +0100, Jonathan Fine wrote: > I wrote: > > > Here is my simple proposal. Enhance Python to allow > > > > >>> hn = def a, b=2, c=3: a ** b / c > > I'd like to add a clarification. Here are two proposals. > > ONE. Wherever you could have used 'lambda', you now

Re: [Python-ideas] A simple proposal concerning lambda

2018-08-22 Thread Steven D'Aprano
On Tue, Aug 21, 2018 at 09:57:51PM -0500, Abe Dillon wrote: > [Chris Angelico] > > > If you have a use-case for a lambda function that takes a callback and > > has a default value for that callback, please submit it to The Daily > > WTF. In Steve's example, the main function was created with a >

Re: [Python-ideas] Does jargon make learning more difficult?

2018-08-22 Thread Steven D'Aprano
On Wed, Aug 22, 2018 at 01:38:03PM -0400, David Mertz wrote: > On Wed, Aug 22, 2018, 12:40 PM Steven D'Aprano wrote: > > > I believe that many people have a lot of trouble grasping the concept of > > functions as first-class values capable of being passed to other fun

Re: [Python-ideas] Does jargon make learning more difficult?

2018-08-23 Thread Steven D'Aprano
I don't have objective evidence for these opinions, but I've tried as best as I am able to give the reasons why I believe this, and not just make it an assertion. > If you honestly don't understand my position at all. [...] > then I guess I've never met anyone quite like you. I'm a uniqu

Re: [Python-ideas] Does jargon make learning more difficult?

2018-08-23 Thread Steven D'Aprano
On Wed, Aug 22, 2018 at 06:50:29PM +, Dan Sommers wrote: > On Thu, 23 Aug 2018 03:44:07 +1000, Steven D'Aprano wrote: > > > On Wed, Aug 22, 2018 at 12:11:40PM -0500, Abe Dillon wrote: > > > difflib tests include this call: > > > > sm = difflib.S

Re: [Python-ideas] Jump to function as an an alternative to call function

2018-08-20 Thread Steven D'Aprano
On Sun, Aug 19, 2018 at 06:18:56PM +0300, Kirill Balunov wrote: [...] > > > e) It leaves a room for a future changes (In fact, in some situations I > > > would like to have this possibility). [Chris] > > Related to (e) is that there is room for other implementations to > > permit changes to

Re: [Python-ideas] Does jargon make learning more difficult?

2018-08-21 Thread Steven D'Aprano
On Tue, Aug 21, 2018 at 02:07:33PM +0900, Stephen J. Turnbull wrote: > I was an economist then, and I'm an economist still, but I met lambda > in 1977. Surely lambda has had that role in computer languages since > shortly before I was born. I would guess anybody above a certain age > would

Re: [Python-ideas] Pre-conditions and post-conditions

2018-08-27 Thread Steven D'Aprano
On Mon, Aug 27, 2018 at 11:00:22PM +1000, Chris Angelico wrote: > Sometimes "type" doesn't mean the same thing to the language and to > the human. Suppose you're trying to create a Python script that > replicates a C program; you might want to declare that a variable is > not of type "integer"

Re: [Python-ideas] Unpacking iterables for augmented assignment

2018-08-26 Thread Steven D'Aprano
On Sun, Aug 26, 2018 at 07:50:49PM +0100, Jonathan Fine wrote: > Hi James and Steve > > Myself and Steve wrote: > > >> Notice that '+=' creates uses the same object when the object is a > >> list, but creates a new object. This raises the question: Why and how > >> does Python behave in this

Re: [Python-ideas] Python-ideas Digest, Vol 141, Issue 145

2018-08-29 Thread Steven D'Aprano
On Wed, Aug 29, 2018 at 01:15:46PM +0100, Oscar Benjamin wrote: > On Tue, 28 Aug 2018 at 08:12, Jacco van Dorp wrote: > > > > Op ma 27 aug. 2018 om 23:18 schreef James Lu : > >> > >> > As Matthew points out, you could use numpy.array. Or code your own > >> > class, by providing __add__ and

Re: [Python-ideas] Pre-conditions and post-conditions

2018-08-29 Thread Steven D'Aprano
On Wed, Aug 29, 2018 at 09:23:02AM +0200, Jacco van Dorp wrote: > Op wo 29 aug. 2018 om 03:59 schreef Steven D'Aprano : > > > On Tue, Aug 28, 2018 at 07:46:02AM +0200, Marko Ristin-Kaufmann wrote: > > > Hi, > > > To clarify the benefits of the contracts, let me give

Re: [Python-ideas] Pre-conditions and post-conditions

2018-08-29 Thread Steven D'Aprano
I didn't want to embarass Ivan any further by seemingly picking on his opinion about contracts being always statically checked, but when I asked off-list I got told to reword and post it here. So here it is. Sorry Ivan if this makes you feel I'm picking on you, that isn't my intention. On

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-19 Thread Steven D'Aprano
On Thu, Jul 19, 2018 at 11:39:50AM -0700, Brendan Barnwell wrote: > On 2018-07-19 06:38, Steven D'Aprano wrote: > >*Its just spelling*. If it is a useful and well-defined feature, we'll > >get used to the spelling soon enough. > > > >That's not to say that spelli

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-19 Thread Steven D'Aprano
On Thu, Jul 19, 2018 at 05:32:48PM +0900, Stephen J. Turnbull wrote: > To be honest, code transformations like this > > > class BaseUploadObject(object): > > def find_content_type(self, filename): > > ctype, encoding = mimetypes.guess_type(filename) > >

Re: [Python-ideas] Idea: Deferred Default Arguments?

2018-07-20 Thread Steven D'Aprano
On Fri, Jul 20, 2018 at 11:03:12AM +0200, Peter O'Connor wrote: > Often when programming I run into a situation where it would be nice to > have "deferred defaults". Here is an example of what I mean: > > def subfunction_1(a=2, b=3, c=4): > return a+b*c > > def

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-20 Thread Steven D'Aprano
On Thu, Jul 19, 2018 at 12:57:01PM +0100, Jonathan Fine wrote: > > Possibly this is exactly the wrong time to propose the next big syntax > > change, since we currently have nobody to declare on it, but since we're > > likely to argue for a while anyway it probably can't hurt [...] > > Perhaps

Re: [Python-ideas] Multi-core reference count garbage collection

2018-07-20 Thread Steven D'Aprano
On Thu, Jul 19, 2018 at 07:33:13AM +0100, Jonathan Fine wrote: > Hi > > Based on other people's work (including in particular talks by Larry > Hastings) and my own thinking, I've come up with a scheme for multi-core > reference count garbage collection. Sorry Jonathan, can you please explain: -

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-20 Thread Steven D'Aprano
On Thu, Jul 19, 2018 at 10:33:21AM +0200, Antoine Pitrou wrote: > def insort_right(a, x, lo=0, hi=None): > # ... > hi = hi else len(a) I read that as "hi, if it is truthy, else len(a)". The advantage of ?? as None-aware operator is that it cannot possibly be misread as

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-20 Thread Steven D'Aprano
On Thu, Jul 19, 2018 at 08:57:50PM -0400, Michael Selik wrote: > Try/except also looks decent. > > try: > x = foo['bar'][0] > except TypeError: > x = 'default' Consider the case that foo['bar'] is supposed to return either a collection (something that can be indexed) or

Re: [Python-ideas] Idea: Deferred Default Arguments?

2018-07-20 Thread Steven D'Aprano
On Fri, Jul 20, 2018 at 04:43:56PM +0200, Peter O'Connor wrote: > I still think it would be nice to have this as a built-in python feature, > for a few reasons: > - When using non-differable functions (say in other codebases), we have to > do a bunch of "func = deferrable_args(func)" at the top

Re: [Python-ideas] Idea: Deferred Default Arguments?

2018-07-20 Thread Steven D'Aprano
On Fri, Jul 20, 2018 at 05:54:44PM +0200, Peter O'Connor wrote: > On Fri, Jul 20, 2018 at 5:41 PM, Steven D'Aprano > wrote: > > > > > > What makes you think that a built-in deferred feature won't have exactly > > the same issues? Do you have an implemen

Re: [Python-ideas] Multi-core reference count garbage collection

2018-07-20 Thread Steven D'Aprano
On Fri, Jul 20, 2018 at 06:37:49PM +0100, Jonathan Fine wrote: > Hi Steve > > You wrote > > Sorry Jonathan, can you please explain: > > > > - what problem you are solving with this? > > > > - and what's wrong with the existing garbage collector? > > The problem I'm trying to solve doing

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-20 Thread Steven D'Aprano
On Fri, Jul 20, 2018 at 12:03:47PM +1200, Greg Ewing wrote: > Rhodri James wrote: > >If anyone can think of a good word for "if it isn't None, otherwise", > >I'd be all for it :-) > > I don't think there's any single Engish word that captures > all of that, so we'd have to invent one. > > Some

Re: [Python-ideas] Multi-core reference count garbage collection

2018-07-20 Thread Steven D'Aprano
On Fri, Jul 20, 2018 at 09:44:39PM +0100, Jonathan Fine wrote: > Hi Steve > > You wrote: > > My understanding is that reference counting is both deterministic and > > immediate. Shifting the reference counting into another thread so that > > it becomes non-deterministic and potentially delayed

Re: [Python-ideas] Add the imath module

2018-07-14 Thread Steven D'Aprano
On Sat, Jul 14, 2018 at 03:39:25PM -0500, Tim Peters wrote: > While my code had no fluff at all. It's hard to believe you could add > enough cruft to slow it down by a factor of 1000, There's a factor of 20 because my computer is older and slower than yours. (I ran your version, and it was

Re: [Python-ideas] Add the imath module

2018-07-13 Thread Steven D'Aprano
On Fri, Jul 13, 2018 at 10:52:38AM -0500, Tim Peters wrote: > Steven's numbers are pretty baffling to me, since these are all composite > and so iterating Miller-Rabin "should get out" pretty fast: That's because you haven't seen my code :-) It's over-engineered, class-based, and written as a

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-23 Thread Steven D'Aprano
On Mon, Jul 23, 2018 at 12:09:00PM +0100, Steve Dower wrote: > On 23Jul2018 1145, Antoine Pitrou wrote: > > > >Le 23/07/2018 à 12:38, Steve Dower a écrit : > >> > >>General comment to everyone (not just Antoine): these arguments have > >>zero value to me. Feel free to keep making them, but I am

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-23 Thread Steven D'Aprano
On Mon, Jul 23, 2018 at 02:04:17PM +0200, Giampaolo Rodola' wrote: [I wrote this] > > This is the point I was making earlier: you accept existing punctuation > > doing these things: > > > > try: > > obj.spam.egsg.tomato.cheese # oops a typo > > except AttributeError: > >

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-23 Thread Steven D'Aprano
On Sun, Jul 22, 2018 at 11:54:19AM +1000, Steven D'Aprano wrote: > In my opinion, writing > > expression if expression is None else default > > is the *opposite* of Pythonic, it is verbose and the DRY violation is > inelegant (as well as inefficient). I

Re: [Python-ideas] A better (simpler) approach to PEP 505

2018-07-23 Thread Steven D'Aprano
On Mon, Jul 23, 2018 at 11:12:45AM -0400, David Mertz wrote: > Here is a way of solving the "deep attribute access to messy data" problem > that is: > > (1) Much more explicit > (2) Requires no change in syntax > (3) Will not be a bug magnet That's one opinion. > (4) Inasmuch as there are

Re: [Python-ideas] A better (simpler) approach to PEP 505

2018-07-23 Thread Steven D'Aprano
On Mon, Jul 23, 2018 at 01:55:48PM -0400, David Mertz wrote: > On Mon, Jul 23, 2018 at 1:28 PM Steven D'Aprano wrote: > > > There's the first bug right there. foo.bar.blim ought to raise > > AttributeError, since there is no blim attribute defined on foo.bar. > >

Re: [Python-ideas] A better (simpler) approach to PEP 505

2018-07-23 Thread Steven D'Aprano
On Mon, Jul 23, 2018 at 10:53:11AM -0700, Grégory Lielens wrote: > The proto here swallow and short circuit on attribute error. Changing > to do it on Noneness is easy, and you can choose between the two > behavior: it's a strength compared to the operator approach. Being able to choose

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-21 Thread Steven D'Aprano
On Sun, Jul 22, 2018 at 01:56:35AM +0200, Giampaolo Rodola' wrote: > On Thu, Jul 19, 2018 at 3:39 PM Steven D'Aprano wrote: > > Tens of thousands of non-English speakers have had to learn the meaning > > of what might as well be meaningless, random sets of symbols (to them)

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-22 Thread Steven D'Aprano
On Sun, Jul 22, 2018 at 12:13:04PM +0200, Giampaolo Rodola' wrote: > On Sun, Jul 22, 2018 at 3:55 AM Steven D'Aprano wrote: [...] > > I don't think that "+" is harder to read than > > "standard_mathematics_operators_numeric_addition" >

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-22 Thread Steven D'Aprano
On Sun, Jul 22, 2018 at 11:26:15PM +1000, Chris Angelico wrote: > You forget that the operator will *short-circuit*. It will not > evaluate the second argument if the first argument is None. You cannot > do this with a function, other than with a hack like a lambda > function. We keep running up

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-22 Thread Steven D'Aprano
On Sun, Jul 22, 2018 at 05:09:39PM +0200, Giampaolo Rodola' wrote: > > > I personally don't find "a ?? b" too bad (let's say I'm -0 about it) > > > but idioms such as "a?.b", "a ??= b" and "a?[3] ?? 4" look too > > > Perl-ish to me, non pythonic and overall not explicit, no matter what > > > the

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-22 Thread Steven D'Aprano
On Mon, Jul 23, 2018 at 12:59:20AM +0200, Giampaolo Rodola' wrote: > You're back at "since we have X that justifies the addition of Y" [1] > and AFAICT that's the only argument you have provided so far in a 100+ > messages discussion. The PEP itself justifies the addition of Y. Chris' argument,

Re: [Python-ideas] Multi-core reference count garbage collection

2018-07-21 Thread Steven D'Aprano
On Sat, Jul 21, 2018 at 11:05:43AM +0100, Daniel Moisset wrote: [snip interesting and informative discussion, thank you] > @Steven D'Aprano: you mentioned soemthign about race conditions but I don't > think this algorithm has any (the article you linked just said that doing > re

Re: [Python-ideas] PEP 505: None-aware operators

2018-07-23 Thread Steven D'Aprano
On Mon, Jul 23, 2018 at 10:48:23AM +0100, Steve Dower wrote: > On 23Jul2018 0151, Steven D'Aprano wrote: > >What if there was a language > >supported, non-hackish way to officially delay evaluation of > >expressions until explicitly requested? > > The current spelling f

<    2   3   4   5   6   7   8   9   10   11   >