[Python-ideas] Re: commonprefix

2024-06-17 Thread Rob Cliffe via Python-ideas
On 13/06/2024 02:20, Rob Cliffe wrote: The os.path.commonprefix function basically returns the common initial characters (if any) shared by a sequence of strings, e.g.     os.path.commonprefix(("Python is great!", "Python is not bad", "Python helps")) # returns "Python " The following was wr

[Python-ideas] Re: commonprefix

2024-06-17 Thread Rob Cliffe via Python-ideas
The os.path.commonprefix function basically returns the common initial characters (if any) shared by a sequence of strings, e.g.     os.path.commonprefix(("Python is great!", "Python is not bad", "Python helps")) # returns "Python " The following was wrong.  os.path.commonprefix uses min and ma

[Python-ideas] commonprefix

2024-06-12 Thread Rob Cliffe via Python-ideas
The os.path.commonprefix function basically returns the common initial characters (if any) shared by a sequence of strings, e.g.     os.path.commonprefix(("Python is great!", "Python is not bad", "Python helps")) # returns "Python " This is purely a string manipulation function which bears no rel

[Python-ideas] Re: SyntaxError: cannot use assignment expressions with attribute

2023-10-10 Thread Rob Cliffe via Python-ideas
The fact that it is not allowed is nothing to do with the 'return'. You *can* write     return (x := x+1) What you can't (at present) do is use the walrus operator with an attribute:     x = (self.a := self.a + 1) # SyntaxError I too have found times when this would be convenient. As Stephen says

[Python-ideas] Re: Extract variable name from itself

2023-09-12 Thread Rob Cliffe via Python-ideas
On 12/09/2023 11:54, Dom Grigonis wrote: Yes, Thank you! So 2 solutions now. They both solve what I have encountered. Beyond that, they differ by: a) f-string print(f’{=a.method}’) # ‘a.method’ No new builtin needed. Simply reprints expression representation. I don't unde

[Python-ideas] Re: Extract variable name from itself

2023-09-12 Thread Rob Cliffe via Python-ideas
As for the example in your first post: var = 710 variable_name = [k fork, v inlocals().items()ifv == 710][0] print("Your variable name is "+ variable_name) it does "work", but it doesn't make much sense with Python's semantics.  You could have two identifiers bound to the same object; which o

[Python-ideas] Re: Have del return a value

2023-09-11 Thread Rob Cliffe via Python-ideas
On 08/09/2023 22:19, Christopher Barker wrote: On Fri, Sep 8, 2023 at 11:00 AM Barry Scott wrote: I see no need for del to return anything, you already have the reference in foo. The times that foo is dropped at module level are rare enough to not need special syntax. I agr

[Python-ideas] Re: Have del return a value

2023-09-11 Thread Rob Cliffe via Python-ideas
On 08/09/2023 22:19, Christopher Barker wrote: On Fri, Sep 8, 2023 at 11:00 AM Barry Scott wrote: I see no need for del to return anything, you already have the reference in foo. The times that foo is dropped at module level are rare enough to not need special syntax. I agr

[Python-ideas] Re: while(tt--)

2023-08-11 Thread Rob Cliffe via Python-ideas
On 04/08/2023 14:02, Niktar Lirik via Python-ideas wrote: Hi Daniil. Yes, you can do almost same:     tt = 5     while tt := tt - 1:     print(tt) "almost" is right.  The OP's version, as far as I can tell, wants to do post-decrement (test tt, then decrement it) so it would "do somethin

[Python-ideas] Re: Conditional 1-line expression in python

2023-08-05 Thread Rob Cliffe via Python-ideas
When can we expect the results of your survey?  (I responded to it.) Best wishes Rob Cliffe On 17/07/2023 21:41, Dom Grigonis wrote: Hi everyone, I am not very keen on long discussions on such matter as I do not think there is much to discuss: there is no technical complexity in it and it doe

[Python-ideas] Re: Proposal for get_or function in Python dictionaries

2023-07-19 Thread Rob Cliffe via Python-ideas
On 15/07/2023 21:08, Dom Grigonis wrote: Just to add. I haven’t thought about evaluation. Thus, to prevent evaluation of unnecessary code, introduction of C-style expression is needed anyways: 1. result = bar is None ? default : bar The below would have to evaluate all arguments, thus not a

[Python-ideas] Re: Undefined type

2023-06-12 Thread Rob Cliffe via Python-ideas
The problem with adding a second None-like type is that gradually it will acquire meaning as a possible value in some contexts.  Maybe not in your code, but in other people's.  Then will there be a request for a 3rd such object?  (4th, 5th ...?). Defining your own sentinel object, as you do, see

[Python-ideas] Re: Warn when iterating over an already exhausted generator

2023-06-12 Thread Rob Cliffe via Python-ideas
On 12/06/2023 21:11, Barry wrote: On 12 Jun 2023, at 16:55, BoppreH via Python-ideas wrote: Then the empty list creates hard-to-track bugs. I'm familiar with the iterator protocol and why the behavior above happens, but couldn't it be prevented? I don’t think so. It is not always a bug tha

[Python-ideas] Re: Make ellipsis an indicator of missing implementation

2023-05-03 Thread Rob Cliffe via Python-ideas
Sorry, -1. Is this really worth the hassle when you can write (more explicitly) def my_fun():    raise NotImplementedError # todo Python has grown steadily more complicated in its lifetime.  Usually for good reasons.  But each additional feature adds to the learning curve and the maintenance b

[Python-ideas] Re: Allowing `str.format` to format one or more parameters instead of all parameters

2023-04-25 Thread Rob Cliffe via Python-ideas
On 21/04/2023 23:20, Samuel Muldoon wrote: # pfr is partially_formatted_result pfr =r"\mathjax{{color}}{{text}}".format(color = "blue") # ERROR! missing parameter `text` result =r"\mathjax{{color}}{{text}}".format(text = "Spanish") # ERROR! missing parameter `color` Is there any reason yo

[Python-ideas] Re: An interface for `mro` methods similar to the interface for `iter`, `getattr`, etc...

2023-03-24 Thread Rob Cliffe via Python-ideas
On 24/03/2023 17:30, Samuel Muldoon wrote: *Additionally, the class named `object` should have a method named `__mro__` and any class which inherits from `object` may override `__mro__`   or inherit the default `* *object* *.__mro__` . * It already has an attribute of that name: >>> object._

[Python-ideas] Re: join() could add separators at start or end

2023-03-14 Thread Rob Cliffe via Python-ideas
I did say in my first post on the subject that I couldn't decide on the best API. I'm hoping that someone can devise a better one that might gain support. I also listed a large number of use cases in the stdlib (which I chose as a conveniently available codebase.  I would expect there to be othe

[Python-ideas] Re: Ampersand operator for strings

2023-03-12 Thread Rob Cliffe via Python-ideas
or s in middle), last.lstrip())) What is harder is to be sure that this would be the expected behaviour when using a `&` operator on strings. Why `'   a' & 'b'` would produce `'a b'` and `'   ' & 'b'` produce `' b'` for exam

[Python-ideas] Re: Ampersand operator for strings

2023-03-11 Thread Rob Cliffe via Python-ideas
On 07/03/2023 09:54, Valentin Berlier wrote: I'm -1 on this. You can easily make a helper that achieves the desired syntax. Presenting "human readable data" isn't just about collapsing spaces, and having your own helper means that you can adjust the formatting to your specific use case if nee

[Python-ideas] Re: join() could add separators at start or end

2023-03-09 Thread Rob Cliffe via Python-ideas
On 09/03/2023 05:25, Bruce Leban wrote: On Wed, Mar 8, 2023 at 4:34 PM Rob Cliffe via Python-ideas wrote: It seems to me that it would be useful to be able to make the str.join() function put separators, not only between the items of its operand, but also optionally at

[Python-ideas] Re: Ampersand operator for strings

2023-03-08 Thread Rob Cliffe via Python-ideas
Bikeshedding: 1) I forgot to mention whether the '&' operator should apply to byte strings as well as to strings.     I propose that it should (some supporting examples below). 2) Joao suggested spelling the operator '|'.     But for me: '|' suggests "or" while '&' suggests "and" and is a more

[Python-ideas] join() could add separators at start or end

2023-03-08 Thread Rob Cliffe via Python-ideas
Having had my last proposal shot down in flames, up I bob with another. 😁 It seems to me that it would be useful to be able to make the str.join() function put separators, not only between the items of its operand, but also optionally at the beginning or end. E.g. '|'.join(('Spam', 'Ham', 'Eggs

[Python-ideas] Re: Ampersand operator for strings

2023-03-07 Thread Rob Cliffe via Python-ideas
You make a very powerful point, Bruce.  Much more so IMO than anyone else has so far. Unless anyone else can find a convincing rebuttal, I withdraw my proposal. Best wishes Rob Cliffe On 07/03/2023 21:49, Bruce Leban wrote: On Sun, Mar 5, 2023 at 7:39 PM Rob Cliffe via Python-ideas wrote

[Python-ideas] Re: Ampersand operator for strings

2023-03-07 Thread Rob Cliffe via Python-ideas
On 07/03/2023 07:26, Stephen J. Turnbull wrote: Rob Cliffe writes: > Perhaps where you're not laying out a table, I'm an economist Oh goody!  *Please* tell me what our Government needs to do to grow the UK economy and curb inflation.  I'll inform my MP immediately. 😁 Seriously though ...

[Python-ideas] Re: Ampersand operator for strings

2023-03-06 Thread Rob Cliffe via Python-ideas
On 06/03/2023 15:49, Stephen J. Turnbull wrote: Steven D'Aprano writes: > I like the look of the & operator for concatenation, so I want to like > this proposal. But I think I will need to see real world code to > understand when it would be useful. I have to second that motion. Pretty

[Python-ideas] Ampersand operator for strings

2023-03-05 Thread Rob Cliffe via Python-ideas
Tl;dr: Join strings together with exactly one space between non-blank text where they join. I propose a meaning for     s1 & s2 where s1 and s2 are strings. Namely, that it should be equivalent to     s1.rstrip() + (' ' if (s1.strip() and s2.strip()) else '') + s2.lstrip() Informally, this wil

[Python-ideas] Re: Idea: Tagged strings in python

2022-12-23 Thread Rob Cliffe via Python-ideas
On 20/12/2022 09:16, Steven D'Aprano wrote: On Mon, Dec 19, 2022 at 05:53:38PM -0800, Ethan Furman wrote: Personally, every other time I've wanted to subclass a built-in data type, I've wanted the built-in methods to return my subclass, not the original class. Caveat: If you were subclassi

[Python-ideas] Re: Idea: Tagged strings in python

2022-12-22 Thread Rob Cliffe via Python-ideas
On 19/12/2022 03:23, David Mertz, Ph.D. wrote: On Sun, Dec 18, 2022 at 8:29 PM Steven D'Aprano wrote: > However, if you want to allow these types to possibly *do* something with > the strings inside (validate them, canonicalize them, do a security check, > etc), I think I

[Python-ideas] Re: Idea: Tagged strings in python

2022-12-22 Thread Rob Cliffe via Python-ideas
On 17/12/2022 16:07, e...@emilstenstrom.se wrote: Python's currently supported string types are just single letter, so the suggestion is to require tagged strings to be at least two letters. Er, no: Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on

[Python-ideas] Re: Enhancing variable scope control

2022-12-04 Thread Rob Cliffe via Python-ideas
On 04/12/2022 17:08, Chris Angelico wrote: On Mon, 5 Dec 2022 at 04:07, Rob Cliffe via Python-ideas wrote: On 30/11/2022 20:27, Anony Mous wrote: Danceswithmice wrote: The idea is that YOU write "local:", and the interpreter, without you ever seeing it, promotes that int

[Python-ideas] Re: Enhancing variable scope control

2022-12-04 Thread Rob Cliffe via Python-ideas
On 30/11/2022 20:27, Anony Mous wrote: Danceswithmice wrote: The idea is that YOU write "local:", and the interpreter, without you ever seeing it, promotes that into a hidden function with a hidden name and a hidden call. --- p.f.moore wrote: > That would make "return" in the local sco

[Python-ideas] Re: Generalized deferred computation in Python

2022-06-22 Thread Rob Cliffe via Python-ideas
Thank you for your proposal David.  At last we have a counter-proposal to talk about.  A few points: (1) (As I pointed out in an earlier post) There is a flaw in using the syntax of an expression PRECEDED by a SOFT keyword:     x     =    later    -y With your proposal, x is assigned a deferre

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Rob Cliffe via Python-ideas
On 18/06/2022 15:51, Stephen J. Turnbull wrote: > This raises another choice: should lazy defaults be evaluated before > entering the body of the function, or at the point where the parameter > is used? Which would be more useful? Both are potentially useful. Yes, both *ARE* potentially

[Python-ideas] Re: Null wildcard in de-structuring to ignore remainder and stop iterating

2022-06-20 Thread Rob Cliffe via Python-ideas
On 20/06/2022 17:39, Jeremiah Paige wrote: On Sat, Jun 18, 2022 at 5:42 PM Rob Cliffe via Python-ideas wrote: To me, the natural implementation of slicing on a non-reusable iterator (such as a generator) would be that you are not allowed to go backwards or even stand

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Rob Cliffe via Python-ideas
On 19/06/2022 04:42, David Mertz, Ph.D. wrote: On Sat, Jun 18, 2022, 9:21 PM Rob Cliffe Sorry again, but IMO discussing any model except one where late-bound defaults are evaluated at function call time is just adding FUD. It's definitely rude to repeatedly state that anyone who's

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-20 Thread Rob Cliffe via Python-ideas
On 19/06/2022 04:42, David Mertz, Ph.D. wrote: On Sat, Jun 18, 2022, 9:21 PM Rob Cliffe Sorry again, but IMO discussing any model except one where late-bound defaults are evaluated at function call time is just adding FUD. It's definitely rude to repeatedly state that anyone who's

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-18 Thread Rob Cliffe via Python-ideas
Sorry, but I think all this talk about lazy evaluation is a big red herring:     (1) Python is not Haskell or Dask.     (2) Lazy evaluation is something Python doesn't have, and would be a HUGE amount of work for Chris (or anyone) to implement (much more, I would think, than he has already put i

[Python-ideas] Re: Null wildcard in de-structuring to ignore remainder and stop iterating

2022-06-18 Thread Rob Cliffe via Python-ideas
To me, the natural implementation of slicing on a non-reusable iterator (such as a generator) would be that you are not allowed to go backwards or even stand still:     mygen[42]     mygen[42] ValueError: Element 42 of iterator has already been used (Apologies if I don't know the difference betw

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-18 Thread Rob Cliffe via Python-ideas
On 18/06/2022 03:28, Steven D'Aprano wrote: On Fri, Jun 17, 2022 at 06:32:36AM +0100, Rob Cliffe wrote: The bar for adding a new hard keyword to Python is very high. Likewise for new syntax. I would suggest less so, provided that it was previously illegal, because it's backward-compatible,

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-16 Thread Rob Cliffe via Python-ideas
On 15/06/2022 23:01, Steven D'Aprano wrote: On Wed, Jun 15, 2022 at 01:58:28PM +0100, Rob Cliffe via Python-ideas wrote: Please.  This has been many times by several people already.  No-one is going to change their mind on this by now.  There's no point in rehashing it and adding no

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-16 Thread Rob Cliffe via Python-ideas
On 17/06/2022 04:23, David Mertz, Ph.D. wrote: I've been scolded that I'm not allowed to post unless I support the PEP. Please do not misrepresent me.  That is NOT what I said. Rob Cliffe Nonetheless, I reiterate that I oppose it. There is no "preponderance" of support, but perhaps a slim majo

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-15 Thread Rob Cliffe via Python-ideas
d version might bridge that gap by introducing "later" or "defer" or "delay" in a narrow context, but not foreclosing its later use more broadly. On Wed, Jun 15, 2022 at 8:38 AM Steven D'Aprano wrote: On Tue, Jun 14, 2022 at 11:59:44AM +0100, Rob Cliffe v

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2022-06-14 Thread Rob Cliffe via Python-ideas
I used to prefer `:=` but coming back to this topic after a long interval I am happy with `=>` and perhaps I even like it more, Chris.😁 The PEP status is "Draft".  What are the chances of something happening any time soon, i.e. the PEP being considered by the Steering Committee?  Or is it still

[Python-ideas] Re: Null wildcard in de-structuring to ignore remainder and stop iterating

2022-06-10 Thread Rob Cliffe via Python-ideas
On 09/06/2022 10:28, Paul Moore wrote: On 09/06/2022 09:50, Paul Moore wrote: On Thu, 9 Jun 2022 at 01:12, Steve Jorgensen wrote: My current thinking in response to that is that using islice is a decent solution except that it's not obvious. You have to jump outside of the thinking about t

[Python-ideas] Re: Null wildcard in de-structuring to ignore remainder and stop iterating

2022-06-09 Thread Rob Cliffe via Python-ideas
On 09/06/2022 09:50, Paul Moore wrote: On Thu, 9 Jun 2022 at 01:12, Steve Jorgensen wrote: My current thinking in response to that is that using islice is a decent solution except that it's not obvious. You have to jump outside of the thinking about the destructuring capability and conside

[Python-ideas] Re: default as a keyword argument for dict.get and dict.pop

2022-06-08 Thread Rob Cliffe via Python-ideas
On 08/06/2022 15:40, Eric V. Smith via Python-ideas wrote: On 6/7/2022 4:59 PM, Chris Angelico wrote: On Wed, 8 Jun 2022 at 00:36, wrote: Hello! Do you know if there has been discussions around why is the default argument is positional only in the dict methods get and pop? I think ```

[Python-ideas] Re: default as a keyword argument for dict.get and dict.pop

2022-06-08 Thread Rob Cliffe via Python-ideas
On 07/06/2022 15:28, martineznicolas41...@gmail.com wrote: I think ``` d.get(key, default=3) ``` way more readable than ``` d.get(key, 3) I completely agree. Best wishes Rob Cliffe ___ Python-ideas mailing list -- python-ideas@python.org To unsu

[Python-ideas] Re: Time to relax some restrictions on the walrus operator?

2022-05-15 Thread Rob Cliffe via Python-ideas
I'm sorry Steven, I didn't mean to denigrate your examples. Please note that I said I was in favour of relaxing the restrictions on the walrus operator. I guess I just meant that using the walrus operator generally adds extra complexity to code and means that more effort is required to read and

[Python-ideas] Re: Time to relax some restrictions on the walrus operator?

2022-05-09 Thread Rob Cliffe via Python-ideas
On 08/05/2022 13:08, Valentin Berlier wrote: A while ago there was a discussion about allowing "match" patterns for the walrus operator. This would cover iterable unpacking as you suggested along with all the patterns allowed in match statements. if [x, y, z] := re.match(r"...").groups(

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Rob Cliffe via Python-ideas
h a function should be part of the standard library. Well, you are 1 user.  Have you evidence that there are (many) others? Best wishes Rob Cliffe --- Original Message --- On Thursday, March 10th, 2022 at 8:38 PM, Rob Cliffe via Python-ideas wrote: This could cause confusion because st

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Rob Cliffe via Python-ideas
On 11/03/2022 19:30, wfdc wrote: > I could (I believe) write "count" as an (inefficient) 1-liner, but not "index". I suggest it's harder than you think. (Try it!) How much harder? Can you post your candidate? It was you that said it could be a 1-liner.  The burden of proof is on you, if yo

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Rob Cliffe via Python-ideas
On 11/03/2022 21:33, wfdc wrote: How about something like def index(self, x):     return next(i for i, a in enumerate(self) if a == x) Including start and end: def index(self, x, start=0, end=-1):     return next(i for i, a in tuple(enumerate(self))[start:end] if a == x) No cigar.  If the el

[Python-ideas] Re: Add a replace method to tuples

2022-03-14 Thread Rob Cliffe via Python-ideas
This is a common scenario on python-list or python-ideas: Someone has an idea that they think is the greatest thing since sliced bread.  They propose it, and feel hurt / rejected when they get pushback instead of everyone jumping up and down and saying how brilliant it is. Sometimes they are do

[Python-ideas] Re: Add a replace method to tuples

2022-03-10 Thread Rob Cliffe via Python-ideas
This could cause confusion because str.replace() has a completely different API. And indeed if a replace method were added to tuples, a fair case could be made for it having the same API, viz.     replace(old, new, count=-1) Whereas your suggestion can be written as a simple 1-liner, as you dem

[Python-ideas] Re: Syntax proposal of for..in..if in regular for loops

2022-03-02 Thread Rob Cliffe via Python-ideas
On 02/03/2022 20:03, David Mertz, Ph.D. wrote: I really am shocked by how many people seem to have broken ENTER keys on their keyboards. You mock.  (As far as I remember you have always opposed new language features/changes.  Correct me if I am wrong.) But the proposal would give people the c

[Python-ideas] Re: Syntax proposal of for..in..if in regular for loops

2022-03-02 Thread Rob Cliffe via Python-ideas
On 02/03/2022 20:03, David Mertz, Ph.D. wrote: I really am shocked by how many people seem to have broken ENTER keys on their keyboards. You mock.  (As far as I remember you are always opposed to new language features/changes.) But the proposal would give people the choice of     Saving a lev

[Python-ideas] Re: Syntax proposal of for..in..if in regular for loops

2022-03-02 Thread Rob Cliffe via Python-ideas
I have had precisely the same idea. It feels better to make this feature general (if introduced at all) than make it specific to 'for' + 'if'. I think there would have to be a rule that any 'if' that appeared on a line with other suite-introducing-statements could not have a corresponding 'else

[Python-ideas] Re: repeat until

2022-03-01 Thread Rob Cliffe via Python-ideas
On 02/03/2022 02:01, Chris Angelico wrote: On Wed, 2 Mar 2022 at 12:33, Rob Cliffe via Python-ideas wrote: On 02/03/2022 01:02, Chris Angelico wrote: On Wed, 2 Mar 2022 at 10:32, Rob Cliffe via Python-ideas wrote: On 01/03/2022 22:25, Chris Angelico wrote: On Wed, 2 Mar 2022 at 09:24

[Python-ideas] Re: repeat until

2022-03-01 Thread Rob Cliffe via Python-ideas
On 02/03/2022 01:02, Chris Angelico wrote: On Wed, 2 Mar 2022 at 10:32, Rob Cliffe via Python-ideas wrote: On 01/03/2022 22:25, Chris Angelico wrote: On Wed, 2 Mar 2022 at 09:24, Steven D'Aprano wrote: On Tue, Mar 01, 2022 at 04:04:31PM +0000, Rob Cliffe via Python-ideas wrote: I

[Python-ideas] Re: repeat until

2022-03-01 Thread Rob Cliffe via Python-ideas
On 01/03/2022 23:57, Ben Rudiak-Gould wrote: On Tue, Mar 1, 2022 at 2:23 PM Steven D'Aprano wrote:     try:         do_this()         if condition: raise MyBreak         do_that()         if condition: raise MyBreak         do_next_step()         if condition: rai

[Python-ideas] Re: repeat until

2022-03-01 Thread Rob Cliffe via Python-ideas
On 01/03/2022 22:25, Chris Angelico wrote: class MyBreak(Exception): pass try: do_this() if condition: raise MyBreak do_that() if condition: raise MyBreak do_next_step() if condition: raise MyBreak do_last_step

[Python-ideas] Re: repeat until

2022-03-01 Thread Rob Cliffe via Python-ideas
On 01/03/2022 22:25, Chris Angelico wrote: On Wed, 2 Mar 2022 at 09:24, Steven D'Aprano wrote: On Tue, Mar 01, 2022 at 04:04:31PM +0000, Rob Cliffe via Python-ideas wrote: I have use cases for "do exactly once". Basically a sequence of actions which can be broken off (when

[Python-ideas] Re: repeat until

2022-03-01 Thread Rob Cliffe via Python-ideas
Without testing, I am sure it would be slower. I suppose it would be reasonable if exceptions are raised in multiple places and the exceptions were given meaningful names. Best wishes Rob Cliffe On 01/03/2022 17:22, om wrote: How does `try/except` (with raise AppropriateException inside the bl

[Python-ideas] Re: repeat until

2022-03-01 Thread Rob Cliffe via Python-ideas
I have use cases for "do exactly once". Basically a sequence of actions which can be broken off (when something goes wrong and the whole process should be aborted, or when something succeeds and there is no need to try alternatives) at various points with `break`.  Thus avoiding multiple if...t

[Python-ideas] Re: Unit variables upon their first appearance

2022-02-05 Thread Rob Cliffe via Python-ideas
Hi Mirmojtaba, thanks for your suggestion. I doubt this idea will fly with this syntax because it could easily be confused with the walrus operator. x := 0 is *almost* legal syntax currently.  In fact (x := 0) is legal, and it is quite possible that at some time in the future     (Dic[fruit]:=0

[Python-ideas] Re: Revisiting a frozenset display literal

2022-01-21 Thread Rob Cliffe via Python-ideas
On 21/01/2022 11:51, Oscar Benjamin wrote: I really don't understand (having read everything above) why anyone prefers {1,2,3}.frozen() over f{1,2,3}. Yes, some people coming from some other languages might get confused (e.g. in Mathematica this is function call syntax) but that's true of any

[Python-ideas] Re: Revisiting a frozenset display literal

2022-01-18 Thread Rob Cliffe via Python-ideas
On 18/01/2022 19:42, MRAB wrote: On 2022-01-18 18:54, Neil Girdhar wrote: Even if f{1} creates a frozenset, I don't think f{} should create a frozenset.  I think it makes more sense to keep f{1: 2} open for frozendict if it ever makes it in.  Also, {} should be consisten with f{} (both shoul

[Python-ideas] Re: Revisiting a frozenset display literal

2022-01-18 Thread Rob Cliffe via Python-ideas
I'm +1 on the idea. I'm happy with the     f{ ... } syntax (although I did suggest something else). We already have letter-prefixes, let's stick to them rather than adding something new (which conceivably might one day find another use). Best wishes Rob Cliffe On 18/01/2022 15:53, Ricky Teachey

[Python-ideas] Re: Revisiting a frozenset display literal

2022-01-16 Thread Rob Cliffe via Python-ideas
On 17/01/2022 00:16, Steven D'Aprano wrote: On Sun, Jan 16, 2022 at 01:11:13PM +0000, Rob Cliffe via Python-ideas wrote: How about     fs{1, 2, 3} What does the "s" add that the set {1, 2, 3} doesn't already tell us? It helps to distinguish it from     f(1, 2, 3)     f

[Python-ideas] Re: Revisiting a frozenset display literal

2022-01-16 Thread Rob Cliffe via Python-ideas
already say a = frozenset({i+1 for i in range(3)}) which is not too bad. On Sun, 16 Jan 2022 at 14:14, Rob Cliffe via Python-ideas wrote: How about fs{1, 2, 3} ? Best wishes Rob Cliffe On 16/01/2022 12:41, Chris Angelico wrote: > On Sun, Jan 16, 2022 at 11

[Python-ideas] Re: Revisiting a frozenset display literal

2022-01-16 Thread Rob Cliffe via Python-ideas
How about     fs{1, 2, 3} ? Best wishes Rob Cliffe On 16/01/2022 12:41, Chris Angelico wrote: On Sun, Jan 16, 2022 at 11:18 PM Steven D'Aprano wrote: On Sun, Jan 16, 2022 at 09:18:40PM +1100, Chris Angelico wrote: While it's tempting, it does create an awkward distinction. f(1, 2, 3) # look

[Python-ideas] Re: Add a `count` argument to `list.remove`

2021-12-21 Thread Rob Cliffe via Python-ideas
Currently list.remove raises ValueError if the element is not in the list. When called with the count argument, should it raise ValueError if there are fewer than `count` occurrences of the element in the list? Best wishes Rob Cliffe On 22/12/2021 00:09, Jeremiah Vivian wrote: I expect some s

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-12 Thread Rob Cliffe via Python-ideas
On 12/12/2021 06:02, Stephen J. Turnbull wrote: Chris Angelico writes: Of course, the *thread* is generally about argument defaults, but "everything" in it is not specifically about defaults. In *this* subthread Eric was arguing for waiting for a facility for *generic* deferral of expression

[Python-ideas] Re: Should Python enforce Type-checking in the future?

2021-12-09 Thread Rob Cliffe via Python-ideas
Please, no, No, NO! It has always been the policy that typing is, and will remain, optional. On 09/12/2021 20:32, deavid wrote: Hi, I would like to hear the opinion of Python's community on enforcing types in the future for the language. I've been using Python as my main language for everything

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-09 Thread Rob Cliffe via Python-ideas
We seem to be arguing in circles and talking past each other here about nomenclature:     f(arg=>dflt) What does it matter if we call it "a default" or "just behaviour in the function" or "a Jabberwocky" or ""? The RELEVANT question should be "Is it useful"? Best wishes Rob Cliffe On 09/12/20

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-08 Thread Rob Cliffe via Python-ideas
_*Objections to PEP 671 - Summary*_ There seems to be a problem understanding what the objections to PEP 671 are.  Chris A wrote: "Part of the problem is that it is really REALLY hard to figure out what the actual objections are. I asked, and the one clear answer I got was one subjective opinio

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-08 Thread Rob Cliffe via Python-ideas
On 08/12/2021 23:09, David Mertz, Ph.D. wrote: On Wed, Dec 8, 2021, 5:55 PM Rob Cliffe via Python-ideas But AIUI (i.e. practically not at all) Dask is about parallel computing, which is not the same thing as deferred evaluation, though doubtless they overlap. Again AIUI, parallel

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-08 Thread Rob Cliffe via Python-ideas
/2021 22:40, David Mertz, Ph.D. wrote: On Wed, Dec 8, 2021, 2:58 PM Rob Cliffe via Python-ideas On 08/12/2021 19:27, Paul Moore wrote: > The reason deferred objects keep coming up is because they *do* have a much more compelling benefit - they help in a much broader range of ca

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-08 Thread Rob Cliffe via Python-ideas
On 08/12/2021 19:27, Paul Moore wrote: The reason deferred objects keep coming up is because they *do* have a much more compelling benefit - they help in a much broader range of cases. That may be true.  I don't know. Can anyone provide some realistic use cases?  I've read the whole thread a

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-07 Thread Rob Cliffe via Python-ideas
On 07/12/2021 18:22, Stephen J. Turnbull wrote: Rob Cliffe via Python-ideas writes: > I think you're making my point. *shrug* You wrote "object", I took you at your word. > You're saying that the object part isn't that hard, but other parts of > it

[Python-ideas] Re: PEP 671 review of default arguments evaluation in other languages

2021-12-06 Thread Rob Cliffe via Python-ideas
On 06/12/2021 23:13, Steven D'Aprano wrote: On Mon, Dec 06, 2021 at 10:17:06AM +0000, Rob Cliffe via Python-ideas wrote: If your language only has one, early binding is better. That's your opinion.  It's not mine.  Witness the Stack Overflow questions asking why `def f(ar

[Python-ideas] Re: PEP 671 review of default arguments evaluation in other languages

2021-12-06 Thread Rob Cliffe via Python-ideas
On 06/12/2021 08:45, Steven D'Aprano wrote: On Sun, Dec 05, 2021 at 05:31:58PM -0700, Finn Mason wrote: Also, on a kind of side note, what would be a situation where early binding is advantageous to late binding? I can't think of one off the top of my head. If your language only has one, ear

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-06 Thread Rob Cliffe via Python-ideas
On 06/12/2021 09:44, Stephen J. Turnbull wrote: Rob Cliffe via Python-ideas writes: > Nobody has attempted (or at least completed) a PEP, never mind an > implementation, of a "generalized deferred object/type", in the last N > years or decades. Haskell anything. R

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-05 Thread Rob Cliffe via Python-ideas
On 05/12/2021 18:37, David Mertz, Ph.D. wrote: On Sun, Dec 5, 2021, 12:33 PM Chris Angelico And quite frankly, the tone of this list is sounding like "shut up, go away, don't do anything, because there are other proposals that nobody can be bothered writing up, but if they existed,

[Python-ideas] Re: PEP 671 review of default arguments evaluation in other languages

2021-12-05 Thread Rob Cliffe via Python-ideas
On 05/12/2021 04:01, David Mertz, Ph.D. wrote: The cost here is that EVERY SINGLE student learning Python needs to add this new construct to their mental load. EVERY book and tutorial needs to be updated. EVERY experienced developer has to spend extra effort understanding and writing code.

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-05 Thread Rob Cliffe via Python-ideas
On 05/12/2021 15:16, Steven D'Aprano wrote: On Wed, Dec 01, 2021 at 12:26:33PM +, Matt del Valle wrote: I'm sure that people will learn the many uses of the arrow symbols. After all, people learn Perl and APL :-) Closer to home, we also learn all the many different uses of the star symbol

[Python-ideas] Re: PEP 671 review of default arguments evaluation in other languages

2021-12-04 Thread Rob Cliffe via Python-ideas
Thank you for doing this research, Steven. The designers of 12 languages have chosen to provide late binding; those of 3 or 4 have provided early binding. I think this is at least tenuous evidence in favour of my belief that late binding is more useful than early binding. Best wishes Rob Cliffe

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Rob Cliffe via Python-ideas
On 04/12/2021 01:06, Chris Angelico wrote: On Sat, Dec 4, 2021 at 11:59 AM Rob Cliffe via Python-ideas wrote: On 03/12/2021 22:38, Chris Angelico wrote: On Sat, Dec 4, 2021 at 8:18 AM Rob Cliffe via Python-ideas wrote: On 03/12/2021 19:32, Adam Johnson wrote: The first unwelcome

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Rob Cliffe via Python-ideas
On 03/12/2021 22:38, Chris Angelico wrote: On Sat, Dec 4, 2021 at 8:18 AM Rob Cliffe via Python-ideas wrote: On 03/12/2021 19:32, Adam Johnson wrote: The first unwelcome surprise was: >>> def func(a=>[]): ... return a ... >&g

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-03 Thread Rob Cliffe via Python-ideas
On 03/12/2021 19:32, Adam Johnson wrote: The first unwelcome surprise was: >>> def func(a=>[]): ... return a ... >>> import inspect >>> inspect.signature(func).parameters['a'].default Ellipsis Here the current behaviour of returning `Ellipsis` is very unfor

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-02 Thread Rob Cliffe via Python-ideas
On 02/12/2021 14:47, Steven D'Aprano wrote: On Thu, Dec 02, 2021 at 11:00:33PM +1100, Chris Angelico wrote: I'm still unsure whether this is a cool feature or an utter abomination: def f(x=...): ... try: print("You passed x as", x) ... except UnboundLocalError: print("You didn't pass

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-02 Thread Rob Cliffe via Python-ideas
On 01/12/2021 06:16, Chris Angelico wrote: I've just updated PEP 671 https://www.python.org/dev/peps/pep-0671/ with some additional information about the reference implementation, and some clarifications elsewhere. *PEP 671: Syntax for late-bound function argument defaults* Questions, for you

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-02 Thread Rob Cliffe via Python-ideas
On 01/12/2021 15:39, David Mertz, Ph.D. wrote: However, even if I assume the mythical future PEP never happens, in terms of readability, a WORD is vastly less confusing than a combination of punctuation that has no obvious or natural interpretation like '=>'.  Or rather, I think that spelli

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-02 Thread Rob Cliffe via Python-ideas
On 02/12/2021 07:05, Brendan Barnwell wrote: On 2021-12-01 18:35, Chris Angelico wrote: In my reference implementation, there is no object that stores it; it's simply part of the function. A good parallel is the if/else expression: x = float("inf") if z == 0 else y/z Is there an object that

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-02 Thread Rob Cliffe via Python-ideas
On 02/12/2021 03:35, Steven D'Aprano wrote: On Wed, Dec 01, 2021 at 05:16:34PM +1100, Chris Angelico wrote: 1) If this feature existed in Python 3.11 exactly as described, would you use it? Yes I would, but probably not as often as counting cases of the "if param is None: ..." idiom might le

[Python-ideas] Re: PEP 671 (late-bound arg defaults), next round of discussion!

2021-12-02 Thread Rob Cliffe via Python-ideas
On 01/12/2021 10:05, Steven D'Aprano wrote: Oh great, now you're going to conflict with walrus... def process(obj:Union[T:=something, List[T]]:=func(x:=expression)+x)->T: We ought to at least try to avoid clear and obvious conflicts between new and existing syntax. Using `:=` is even w

[Python-ideas] Re: Should bare logical comparisons raise a warning?

2021-11-25 Thread Rob Cliffe via Python-ideas
On 26/11/2021 00:12, Steven D'Aprano wrote: On Wed, Nov 24, 2021 at 07:15:58PM -, ehmatt...@gmail.com wrote: 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

[Python-ideas] Re: Make the global/nonlocal keyword a prefix

2021-11-16 Thread Rob Cliffe via Python-ideas
On 14/11/2021 18:22, Chris Angelico wrote: IMO it would be kinda handy to be able to combine a global statement with an assignment, but it's not a particularly high priority for me. It would reduce a bit of repetition, but that's all. Agreed.  Sometimes I'd like to be able to write this sort

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-11-08 Thread Rob Cliffe via Python-ideas
On 05/11/2021 15:57, Stephen J. Turnbull wrote: Still on the agenda as far as I can see: 1. Syntax. The proposals I can recall are a. x=>default b. *x=default c. x=@default d. maybe putting * or @ on the opposite component in b and c? e. a keyword before default

[Python-ideas] Re: PEP 671: Syntax for late-bound function argument defaults

2021-11-04 Thread Rob Cliffe via Python-ideas
Taking a step back: Suppose Python didn't have default values AT ALL for function parameters?  Say that unpassed parameters were always set to some sentinel value (maybe None, maybe some special value NotPassed). Would we want to add them to the language? Surely almost everybody would say yes.

  1   2   3   >