[Python-ideas] Re: New explicit methods to trim strings

2020-03-22 Thread Kyle Stanley
Stephen J. Turnbull wrote: > The only cases I can remember are files named things like > "thesis.doc.doc" in GUI environments. ;-) For edge cases like that, something like `"thesis.doc.doc".removesuffix(".doc").removesuffix(".doc")` should suffice, no? It may not be the cleanest looking solution,

[Python-ideas] Re: New explicit methods to trim strings

2020-03-22 Thread Stephen J. Turnbull
Paul Moore writes: > I've needed to remove one prefix/suffix. I've never needed to remove > more than one. The only cases I can remember are files named things like "thesis.doc.doc" in GUI environments. ;-) ___ Python-ideas mailing list --

[Python-ideas] Developer messages on install (pip, poetry, etc.)

2020-03-22 Thread Ronie Martinez
Good day! I have been developing in Node for a few months now for non-Python projects (legacy project) and I found a NPM feature which could be helpful to developers of Python libraries. When you install a NPM package, some show a message from the author after installation (see example below).

[Python-ideas] Re: Instance method to test equivalence between set and iterable

2020-03-22 Thread Guido van Rossum
On Sun, Mar 22, 2020 at 6:51 PM Steven D'Aprano wrote: > We might have a terminology issue here, since according to Wikipedia > there is some dispute over whether or not to include the equality case > in subset/superset: > > https://en.wikipedia.org/wiki/Subset > > For what it is worth, I'm in

[Python-ideas] Re: Instance method to test equivalence between set and iterable

2020-03-22 Thread Andrew Barnert via Python-ideas
> On Mar 22, 2020, at 18:54, Steven D'Aprano wrote: > > Do you have an example of `A <= B and B <= A` aside from the `A == B` > case? For mathematical sets, this is either impossible by definition, or impossible by 2-line proof, depending on which definitions you like. For Python sets,

[Python-ideas] Re: Syntax for loop invariants

2020-03-22 Thread Cameron Simpson
On 21Mar2020 12:15, Stephen J. Turnbull wrote: Steven D'Aprano writes: > So each loop will need its own context manager, meaning its own > class. The *actual* invariant will be buried far away, in a CM > class, rather than right there next to the loop. I see no reason why that will be true

[Python-ideas] Re: Instance method to test equivalence between set and iterable

2020-03-22 Thread Kyle Stanley
Steve Jorgensen wrote: > Basically, it is for a sense of completeness. It feels weird that there is a way to check whether an iterable is a subset of a set or a superset > of a set but no way to directly ask whether it is equivalent to the set. I can't say this has never happened historically,

[Python-ideas] Re: Instance method to test equivalence between set and iterable

2020-03-22 Thread Christopher Barker
> there is a way to check whether an iterable is a subset of a set or a > > superset of a set but no way to directly ask whether it is equivalent > > to the set. A_set == set(an_iterable) Seems straightforward to me :-) I see that subset will accept an arbitrary iterable, whereas __eq__ does

[Python-ideas] Re: Instance method to test equivalence between set and iterable

2020-03-22 Thread Steven D'Aprano
On Mon, Mar 23, 2020 at 12:08:23AM -, Steve Jorgensen wrote: > Basically, it is for a sense of completeness. It feels weird that > there is a way to check whether an iterable is a subset of a set or a > superset of a set but no way to directly ask whether it is equivalent > to the set. I

[Python-ideas] Re: Instance method to test equivalence between set and iterable

2020-03-22 Thread Steven D'Aprano
On Mon, Mar 23, 2020 at 12:03:50AM -, Steve Jorgensen wrote: > Every set is a superset of itself and a subset of itself. A set may > not be a "formal" subset or a "formal" superset of itself. `issubset` > and `issuperset` refer to standard subsets and supersets, not formal > subsets and

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-22 Thread Kyle Stanley
I ended up opening an issue for it at https://bugs.python.org/issue40045. On Sun, Mar 22, 2020 at 8:33 PM Kyle Stanley wrote: > Chistopher Barker wrote: > > I'd suggest you make a PR on the docs. > > Yeah I was planning on either doing that, or opening it as a "newcomer

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-22 Thread Kyle Stanley
Chistopher Barker wrote: > I'd suggest you make a PR on the docs. Yeah I was planning on either doing that, or opening it as a "newcomer friendly"/"easy" issue on bugs.python.org. IMO, it could make for a decent first PR. On Sun, Mar 22, 2020 at 1:28 PM Christopher Barker wrote: > On Fri, Mar

[Python-ideas] Re: Instance method to test equivalence between set and iterable

2020-03-22 Thread Steve Jorgensen
Paul Moore wrote: > On Sun, 22 Mar 2020 at 20:01, Steve Jorgensen ste...@stevej.name wrote: > > > > Currently, the issubset and > > issuperset methods of set objects accept arbitrary iterables as arguments. > > An > > iterable that is both a subset and superset is, in a sense, "equal" to the > >

[Python-ideas] Re: Instance method to test equivalence between set and iterable

2020-03-22 Thread Steve Jorgensen
Steven D'Aprano wrote: > On Sun, Mar 22, 2020 at 07:59:59PM -, Steve Jorgensen wrote: > > Currently, the issubset and > > issuperset methods of set objects > > accept arbitrary iterables as arguments. An iterable that is both a > > subset and superset is, in a sense, "equal" to the set. It

[Python-ideas] Re: Instance method to test equivalence between set and iterable

2020-03-22 Thread Steven D'Aprano
On Sun, Mar 22, 2020 at 07:59:59PM -, Steve Jorgensen wrote: > Currently, the `issubset` and `issuperset` methods of set objects > accept arbitrary iterables as arguments. An iterable that is both a > subset and superset is, in a sense, "equal" to the set. It would be > inappropriate for

[Python-ideas] Re: Instance method to test equivalence between set and iterable

2020-03-22 Thread Paul Moore
On Sun, 22 Mar 2020 at 20:01, Steve Jorgensen wrote: > > Currently, the `issubset` and `issuperset` methods of set objects accept > arbitrary iterables as arguments. An iterable that is both a subset and > superset is, in a sense, "equal" to the set. It would be inappropriate for > `==` to

[Python-ideas] Re: Instance method to test equivalence between set and iterable

2020-03-22 Thread Rob Cliffe via Python-ideas
On 22/03/2020 19:59, Steve Jorgensen wrote: Currently, the `issubset` and `issuperset` methods of set objects accept arbitrary iterables as arguments. An iterable that is both a subset and superset is, in a sense, "equal" to the set. It would be inappropriate for `==` to return `True` for

[Python-ideas] Re: Instance method to test equivalence between set and iterable

2020-03-22 Thread Steve Jorgensen
Bar Harel wrote: > Hey Steve, > How about set.symmetric_difference()? > Does it not do what you want? > Best regards, > Bar Harel > On Sun, Mar 22, 2020, 10:03 PM Steve Jorgensen ste...@stevej.name wrote: > > Currently, the issubset and > > issuperset methods of set objects accept > > arbitrary

[Python-ideas] Re: Instance method to test equivalence between set and iterable

2020-03-22 Thread Bar Harel
Hey Steve, How about set.symmetric_difference()? Does it not do what you want? Best regards, Bar Harel On Sun, Mar 22, 2020, 10:03 PM Steve Jorgensen wrote: > Currently, the `issubset` and `issuperset` methods of set objects accept > arbitrary iterables as arguments. An iterable that is both

[Python-ideas] Instance method to test equivalence between set and iterable

2020-03-22 Thread Steve Jorgensen
Currently, the `issubset` and `issuperset` methods of set objects accept arbitrary iterables as arguments. An iterable that is both a subset and superset is, in a sense, "equal" to the set. It would be inappropriate for `==` to return `True` for such a comparison, however, since that would

[Python-ideas] Re: New explicit methods to trim strings

2020-03-22 Thread Paul Moore
On Sun, 22 Mar 2020 at 17:58, Guido van Rossum wrote: > > On Sun, Mar 22, 2020 at 9:54 AM Christopher Barker > wrote: >> >> On Sun, Mar 22, 2020 at 2:08 AM Barry Scott wrote: >>> >>> >>> Should `-+-+-+Spam'.stripprefix('-+') remove just the first occurence? >>> >>> All of them? Does it

[Python-ideas] Re: Add the imath module

2020-03-22 Thread Chris Angelico
On Mon, Mar 23, 2020 at 5:13 AM Neil Girdhar wrote: > > I mean: > > def binom(n, *ks): > # Check that there is at least one ki, and that their sum is less than n, > and that they are all nonnegative. > # Returns n! / (prod(ki! for ki in ks) * (n-sum(ks))!) > > This would still work for

[Python-ideas] Re: Add the imath module

2020-03-22 Thread Neil Girdhar
I mean: def binom(n, *ks): # Check that there is at least one ki, and that their sum is less than n, and that they are all nonnegative. # Returns n! / (prod(ki! for ki in ks) * (n-sum(ks))!) This would still work for binom(n, k), but would also work for the mulinomial case. On Sunday,

[Python-ideas] Re: Add the imath module

2020-03-22 Thread Neil Girdhar
I really like this idea. It fixes the weirdness whereby cmath is for complex numbers, and math is for real numbers and integers. I like separating them into three categories. One suggestion: Consider generalizing binom to the multinomial coefficent. def binom(n, *ks): # Returns n! /

[Python-ideas] Re: New explicit methods to trim strings

2020-03-22 Thread Guido van Rossum
On Sun, Mar 22, 2020 at 9:54 AM Christopher Barker wrote: > On Sun, Mar 22, 2020 at 2:08 AM Barry Scott > wrote: > >> >>> Should `-+-+-+Spam'.stripprefix('-+') remove just the first >> occurence? All of them? Does it need a 'count' parameter? >> >> The only ways to use this function without

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-22 Thread Christopher Barker
On Fri, Mar 20, 2020 at 8:24 PM Stephen J. Turnbull < turnbull.stephen...@u.tsukuba.ac.jp> wrote: > Single leading underscore is reserved for class-private use, so you > could more safely use "sunders" (_pretty_) or "splunders" (_pretty__). > Though this use case really isn't "class-private" --

[Python-ideas] Re: New explicit methods to trim strings

2020-03-22 Thread Christopher Barker
On Sun, Mar 22, 2020 at 10:08 AM Chris Angelico wrote: > > I imagine that the count=1 is the most common use case for replace() > anyway, > > > > Do you mean "other than not specifying the count", yes, that -- most common use case for using count at all. I'm suggesting that if -1 and 1 were

[Python-ideas] Re: dunder methods for encoding & prettiness aware formal & informal representations

2020-03-22 Thread Christopher Barker
On Fri, Mar 20, 2020 at 8:52 PM Kyle Stanley wrote: > > > https://docs.python.org/3/reference/lexical_analysis.html#reserved-classes-of-identifiers > > I remembered the existence of this rule and tried to locate it recently > (prior to this discussion), but was unable to because it doesn't

[Python-ideas] Re: New explicit methods to trim strings

2020-03-22 Thread Chris Angelico
On Mon, Mar 23, 2020 at 3:53 AM Christopher Barker wrote: > > On Sun, Mar 22, 2020 at 2:08 AM Barry Scott wrote: >> >> >>> Should `-+-+-+Spam'.stripprefix('-+') remove just the first occurence? >> >>> All of them? Does it need a 'count' parameter? >> >> The only ways to use this function

[Python-ideas] Re: New explicit methods to trim strings

2020-03-22 Thread Christopher Barker
On Sun, Mar 22, 2020 at 2:08 AM Barry Scott wrote: > >>> Should `-+-+-+Spam'.stripprefix('-+') remove just the first > occurence? All of them? Does it need a 'count' parameter? > >> The only ways to use this function without counting is remove 1 prefix > or remove all. > I imagine that the

[Python-ideas] Re: New explicit methods to trim strings

2020-03-22 Thread Barry Scott
> On 19 Mar 2020, at 22:12, Rob Cliffe wrote: > > > On 18/03/2020 20:16, Barry Scott wrote: >> >>> On 18 Mar 2020, at 18:03, Rob Cliffe via Python-ideas >>> wrote: >>> >>> Consider that the start or end of a string may contain repetitions of an >>> affix. >>> >>> Should