[Python-ideas] Re: [Python-Dev] Re: PEP 618: Add Optional Length-Checking To zip

2020-05-19 Thread Ethan Furman
On 05/17/2020 12:02 PM, Rob Cliffe via Python-ideas wrote: On 17/05/2020 19:43, David Mertz wrote: The API matter is really orthogonal to this. My point here is that Nathan and some other discussants are operating under the assumption that: "Everyone really wants strict-zip but they just

[Python-ideas] Re: Optional keyword arguments

2020-05-19 Thread Rob Cliffe via Python-ideas
On 17/05/2020 20:17, James Lu wrote: Many a python programmer have tired to see code written like: def bar(a1, a2, options=None): if options is None: options = {} ... # rest of function syntax if argument is not passed, evaluate {} and store to options def foo(options:={}):

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread David Mertz
On Tue, May 19, 2020 at 8:43 PM Cameron Simpson wrote: > >salt = salt.rstrip("=", maxstrip=2) > >assert not salt.endswith("=") > > Reiterating the Python 3.9 suggestion, what about: > > salt2 = salt.cutsuffix(('==', '=')) > You'd have to call cutsuffix twice. Valid base64 might end in one,

[Python-ideas] Re: Optional keyword arguments

2020-05-19 Thread James Lu
The "if arg is None: arg = " pattern occurs in the standard library eighty-five (85) times. This command was used to find the count: ~/cpython/Lib$ perl -wln -e "/(?s)^(\s*)[^\n]if ([a-zA-Z_]+) is None:(\n)?\s+\2\s*=\s*/s and print" ** ___

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Cameron Simpson
On 19May2020 15:43, David Mertz wrote: I may be misunderstanding, but it sounds like = is not acceptable in the final result, so it's not enough to remove only 2 of 4 ='s. You want to make sure nothing messed up your string. So if the code existed, what you'd want is: ``` assert

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread David Mertz
On Tue, May 19, 2020 at 3:50 PM Alex Hall wrote: > Anyway, you could write: > assert not salt.endswith("=" * 3) # at most 2 ='s allowed > salt = salt.rstrip("=") > Yes, I *could* write that. It feels a bit more cryptic than the version I mentioned. But it's fine. -- The dead increasingly

[Python-ideas] Re: Optional keyword arguments

2020-05-19 Thread Eric V. Smith
On 5/19/2020 4:53 PM, Rob Cliffe via Python-ideas wrote: I have already replied to the OP and to the list, but there seems to be a problem with my posts getting through, so let me try again.  Apologies if you see this twice: To strip at most 1 character from the end:     txt[:-1] +

[Python-ideas] Re: Optional keyword arguments

2020-05-19 Thread Rob Cliffe via Python-ideas
I have already replied to the OP and to the list, but there seems to be a problem with my posts getting through, so let me try again.  Apologies if you see this twice: To strip at most 1 character from the end:     txt[:-1] + txt[-1:].rstrip(chars) To strip at most N characters:     txt[:-N] +

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Alex Hall
On Tue, May 19, 2020 at 9:43 PM David Mertz wrote: > Currently, I'd probably program my intention like this. Let's assume this > is something where the '=' is allowed in the middle. > Getting increasingly hypothetical... Anyway, you could write: ``` assert not salt.endswith("=" * 3) # at

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread David Mertz
> > I may be misunderstanding, but it sounds like = is not acceptable in the > final result, so it's not enough to remove only 2 of 4 ='s. You want to > make sure nothing messed up your string. So if the code existed, what you'd > want is: > ``` > assert salt.count("=") <= 2 > salt =

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Alex Hall
On Tue, May 19, 2020 at 2:58 PM computermaster360 . < computermaster...@gmail.com> wrote: > I often find myself in a need of stripping only a specified amount of > characters from a string (most commonly a single character). I have been > implementing this in an ad-hoc manner, which is quite

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Alex Hall
On Tue, May 19, 2020 at 8:49 PM David Mertz wrote: > elif fmt == "PBKDF2_SHA256": > h = base64.b64encode(base64.b64decode(text)[:32]) > # a terrible hack follows, use "adapted base64" alphabet > (using . instead of + and with no padding) > h =

[Python-ideas] Re: type hints : I'd like to suggest allowing unicode → as an alternative to ->

2020-05-19 Thread Christopher Barker
On Tue, May 19, 2020 at 11:31 AM Brett Cannon wrote: > I'm going to ask that people please try to keep this thread on-topic to > the question of using Unicode characters directly for things that we > currently use two ASCII characters to represent. > Indeed -- and also: please refer to earlier

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread David Mertz
I did a couple greps of my git/ directory to see if I found examples. Given that there are a couple ways one might achieve the effect now, I don't necessarily find everything. But here's something in software I did not write myself. This is from ./JohnTheRipper/run/sspr2john.py. I found another

[Python-ideas] Re: Ensuring asserts are always on in a file

2020-05-19 Thread Brett Cannon
The closest you may ever get to something like this is a clean separation of -O flags instead of the current -O/-OO options. That way you can flip on everything *but* assertion removal. But a per-file directive I don't see happening, and even the flag separation has never caught on enough for

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Alex Hall
On Tue, May 19, 2020 at 8:10 PM Henk-Jaap Wagenaar < wagenaarhenkj...@gmail.com> wrote: > David (or somebody else) could you give us some, as real as possible, > examples? This will strengthen the case for it! > > I am confident they exist and are pretty plentiful but I myself am coming > up

[Python-ideas] Re: type hints : I'd like to suggest allowing unicode → as an alternative to ->

2020-05-19 Thread Brett Cannon
I'm going to ask that people please try to keep this thread on-topic to the question of using Unicode characters directly for things that we currently use two ASCII characters to represent. Other ideas that spring up from this question are totally welcome to be done as new threads of discussion.

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Henk-Jaap Wagenaar
David (or somebody else) could you give us some, as real as possible, examples? This will strengthen the case for it! I am confident they exist and are pretty plentiful but I myself am coming up blank thinking about it for a few minutes and documenting them would be good for discussion. On Tue,

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread David Mertz
I think this would be useful, and doesn't break any backward compatibility. I would have use for it from time to time myself. On Tue, May 19, 2020 at 9:01 AM computermaster360 . < computermaster...@gmail.com> wrote: > I often find myself in a need of stripping only a specified amount of >

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread computermaster360 .
Jonathan Goble wrote: > > Do you mean "str.strip, str.lstrip, str.rstrip"? Yes, I meant that. ___ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Rob Cliffe via Python-ideas
To strip at most 1 character from the end:     txt[:-1] + txt[-1:].rstrip(chars) To strip at most N characters:     txt[:-N] + txt[-N:].rstrip(chars) Given that, I think yours is too much of a niche case to change anything in Python Rob Cliffe On 19/05/2020 12:44, computermaster360 . wrote: I

[Python-ideas] Re: str.strip: argument maxstrip

2020-05-19 Thread Jonathan Goble
On Tue, May 19, 2020 at 9:00 AM computermaster360 . < computermaster...@gmail.com> wrote: > I often find myself in a need of stripping only a specified amount of > characters from a string (most commonly a single character). I have been > implementing this in an ad-hoc manner, which is quite

[Python-ideas] str.strip: argument maxstrip

2020-05-19 Thread computermaster360 .
I often find myself in a need of stripping only a specified amount of characters from a string (most commonly a single character). I have been implementing this in an ad-hoc manner, which is quite inelegant: def rstrip1(txt, chars): if txt is None: return None elif any(txt.endswith(c)

[Python-ideas] Re: [Python-Dev] Re: PEP 618: Add Optional Length-Checking To zip

2020-05-19 Thread Rob Cliffe via Python-ideas
On 17/05/2020 19:43, David Mertz wrote: On Sun, May 17, 2020 at 2:09 PM Nathan Schneider > wrote: If you want a better metaphor: Some door handles include locks, others do not.  "Strict" ones have locks.  So yes, it's possible to leave the

[Python-ideas] Re: Optional keyword arguments

2020-05-19 Thread Henk-Jaap Wagenaar
I think only using the first third of the quote makes your argument too terse Steven. To include the second part: "There should be one-- and preferably only one" which implies "It is preferable there is exactly one qualified pilot in the cockpit", and we arrive (if abbreviated) at what James