[Python-Dev] Re: PEP 616 -- String methods to remove prefixes and suffixes

2020-03-23 Thread Dan Stromberg
On Fri, Mar 20, 2020 at 3:28 PM Victor Stinner  wrote:

> > The builtin ``str`` class will gain two new methods with roughly the
> > following behavior::
> >
> > def cutprefix(self: str, pre: str, /) -> str:
> > if self.startswith(pre):
> > return self[len(pre):]
> > return self[:]
>

I tend to be mistrustful of code that tries to guess the best thing to do,
when something expected isn't found.

How about:

def cutprefix(self: str, pre: str, raise_on_no_match: bool=False, /) -> str:
if self.startswith(pre):
return self[len(pre):]
if raise_on_no_match:
raise ValueError('prefix not found')
return self[:]
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/NYMLVK35CVNWUL6OWZDB2CRA5W2HPMIH/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 616 -- String methods to remove prefixes and suffixes

2020-03-23 Thread Rhodri James

On 23/03/2020 14:50, Dan Stromberg wrote:

On Fri, Mar 20, 2020 at 3:28 PM Victor Stinner  wrote:


The builtin ``str`` class will gain two new methods with roughly the
following behavior::

 def cutprefix(self: str, pre: str, /) -> str:
 if self.startswith(pre):
 return self[len(pre):]
 return self[:]




I tend to be mistrustful of code that tries to guess the best thing to do,
when something expected isn't found.

How about:

def cutprefix(self: str, pre: str, raise_on_no_match: bool=False, /) -> str:
 if self.startswith(pre):
 return self[len(pre):]
 if raise_on_no_match:
 raise ValueError('prefix not found')
 return self[:]


I'm firmly of the opinion that the functions should either raise or not, 
and should definitely not have a parameter to switch behaviours. 
Probably it should do nothing; if the programmer needs to know that the 
prefix wasn't there, cutprefix() probably wasn't the right thing to use 
anyway.


--
Rhodri James *-* Kynesim Ltd
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/SA5RZNAJESODSMNGBX7OD2F77YMHWH5Z/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Jump on C by PyEval_SetTrace Python 3.7.7

2020-03-23 Thread Victor Stinner
Hi,

It seems like you should be to modify frame->f_lasti in a trace function

FYI in a frame object, the line number is computed using
frame->f_lasti and f->f_code->co_lnotab: PyFrame_GetLineNumber().

See: https://github.com/python/cpython/blob/master/Objects/lnotab_notes.txt

Good luck ;-)

Victor

Le lun. 23 mars 2020 à 00:50, Leandro Müller
 a écrit :
>
> Hi everyone.
>
> I'm trying to make a simple jump on C funcion trace by frame->f_lineno.
> Example is simple, but not working.
>
>
> if (frame->f_lineno == 12){
>
> frame->f_lineno = 8;
>
> }
>
> attached files C and python to run test.
> the line 12 I need to jump to line 8.
>
>
>
> Att.
>
> Leandro Müller
>
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python-dev@python.org/message/7RZX4MUF6GLPU4DVXLRTQ534TDRXRL36/
> Code of Conduct: http://python.org/psf/codeofconduct/



-- 
Night gathers, and now my watch begins. It shall not end until my death.
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/NRZM3MYRESKG6HCX44KEQINIRYYTKVDO/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 616 -- String methods to remove prefixes and suffixes

2020-03-23 Thread Eric V. Smith

On 3/23/2020 12:02 PM, Rhodri James wrote:

On 23/03/2020 14:50, Dan Stromberg wrote:


I tend to be mistrustful of code that tries to guess the best thing 
to do,

when something expected isn't found.

How about:

def cutprefix(self: str, pre: str, raise_on_no_match: bool=False, /) 
-> str:

 if self.startswith(pre):
 return self[len(pre):]
 if raise_on_no_match:
 raise ValueError('prefix not found')
 return self[:]


I'm firmly of the opinion that the functions should either raise or 
not, and should definitely not have a parameter to switch behaviours. 
Probably it should do nothing; if the programmer needs to know that 
the prefix wasn't there, cutprefix() probably wasn't the right thing 
to use anyway.


Agreed, and I think we shouldn't raise. If raising is important, the 
user can write a trivial wrapper that raises if no substitution was 
done. Let's not over-complicate this.


Eric
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/NYJMGSLPW4KFOYUT6ZWL6PSKXCF3EDHM/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Accepting PEP 573 (Module State Access from C Extension Methods)

2020-03-23 Thread Stefan Behnel
As (first-time) BDFL delegate, I accept PEP 573 for Python 3.9,
"Module State Access from C Extension Methods"

https://www.python.org/dev/peps/pep-0573/

Petr, Nick, Eric and Marcel, thank you for your work and intensive
discussions on this PEP, and also to everyone else who got involved on
mailing lists, sprints and conferences.

It was a long process with several iterations, much thinking, rethinking
and cutting down along the way, Python 3.7 *and* 3.8 being missed, but 3.9
now finally being hit. Together with several other improvements to the
C-API in the upcoming release, this will help making extension modules less
"different" and easier to adapt for subinterpreters.

Best,
Stefan
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/MRM5KDM3ITIE6ROK336UQGHKFANYWX6R/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Jump on C by PyEval_SetTrace Python 3.7.7

2020-03-23 Thread Leandro Müller
Hi.
When I changed frame->f_lasti change de code to back, it's work but the line in 
front code occurs dump, the runtime over.
Example:
I jump to 8 line and after I jump to line 10, it occurs dump.

On python trace pdb the jump works good by the frame-f_lineno.


Att.

Leandro Müller


De: Victor Stinner 
Enviado: segunda-feira, 23 de março de 2020 13:01
Para: Leandro Müller 
Cc: python-dev@python.org 
Assunto: Re: [Python-Dev] Jump on C by PyEval_SetTrace Python 3.7.7

Hi,

It seems like you should be to modify frame->f_lasti in a trace function

FYI in a frame object, the line number is computed using
frame->f_lasti and f->f_code->co_lnotab: PyFrame_GetLineNumber().

See: https://github.com/python/cpython/blob/master/Objects/lnotab_notes.txt

Good luck ;-)

Victor

Le lun. 23 mars 2020 à 00:50, Leandro Müller
 a écrit :
>
> Hi everyone.
>
> I'm trying to make a simple jump on C funcion trace by frame->f_lineno.
> Example is simple, but not working.
>
>
> if (frame->f_lineno == 12){
>
> frame->f_lineno = 8;
>
> }
>
> attached files C and python to run test.
> the line 12 I need to jump to line 8.
>
>
>
> Att.
>
> Leandro Müller
>
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python-dev@python.org/message/7RZX4MUF6GLPU4DVXLRTQ534TDRXRL36/
> Code of Conduct: http://python.org/psf/codeofconduct/



--
Night gathers, and now my watch begins. It shall not end until my death.
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/GMQE4A2A3AEDNXKJA67MSTEZXZ3XRC7Y/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Accepting PEP 573 (Module State Access from C Extension Methods)

2020-03-23 Thread Hai Shi
Wow, congratulations!

ps: two days ago, I asked petr what blocked PEP-573 privately(mch extension 
module need this pep ;))
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/C4XQJF7WFHUO5WRIVPDN44BFP3SYB3Q6/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Accepting PEP 573 (Module State Access from C Extension Methods)

2020-03-23 Thread Hai Shi
Wow, congratulations:)

Looking forword to Marcel' PRs:
https://github.com/python/cpython/compare/master...Dormouse759:pep-c-rebase_newer

ps: two days ago, I asked what blocked pep-0573 privately ;)
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/OILQKXDLN4UE4YTXNIBMNM7C3NLJCZL2/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 616 -- String methods to remove prefixes and suffixes

2020-03-23 Thread Rob Cliffe via Python-Dev
Sorry, another niggle re handling an empty affix:  With your Python 
implementation,

'aba'.cutprefix(('', 'a')) == 'aba'
'aba'.cutsuffix(('', 'a')) == 'ab'
This seems surprising.
Rob Gadfly Cliffe


On 22/03/2020 23:23, Dennis Sweeney wrote:

Much appreciated! I will add that single quote and change those snippets to::

  >>> s = 'FooBar' * 100 + 'Baz'
  >>> prefixes = ('Bar', 'Foo')
  >>> while len(s) != len(s := s.cutprefix(prefixes)): pass
  >>> s
  'Baz'

and::

  >>> s = 'FooBar' * 100 + 'Baz'
  >>> prefixes = ('Bar', 'Foo')
  >>> while s.startswith(prefixes): s = s.cutprefix(prefixes)
  >>> s
  'Baz'
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/QJ54X6WHQQ5HFROSJOLGJF4QMFINMAPY/
Code of Conduct: http://python.org/psf/codeofconduct/

___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/XZD7TRPNXNVL4FL4NNUX6KB3OREVALCX/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Jump on C by PyEval_SetTrace Python 3.7.7 - SOLUTION

2020-03-23 Thread Leandro Müller
Hello Victor Stinner.

Thanks.
Your tip helped me a lot.
I understood that I need to get position on bycode of the line.
So I create the funcion to get position inside of the bycode.
Now I can to jump the correct position on trace.

frame->f_lasti = checkBycodePosition(frame->f_code, 11);


int checkBycodePosition(PyCodeObject *co, int fline)
{
Py_ssize_t size = PyBytes_Size(co->co_lnotab) / 2;
unsigned char *p = (unsigned char *)PyBytes_AsString(co->co_lnotab);
int line = co->co_firstlineno;
int addr = 0;
while (--size >= 0)
{
addr += *p++;

line += (signed char)*p;

if (line == fline)
break;

p++;
}
return addr;
}




Att.

Leandro Müller


De: Leandro Müller 
Enviado: segunda-feira, 23 de março de 2020 13:45
Para: Victor Stinner 
Cc: python-dev@python.org 
Assunto: [Python-Dev] Re: Jump on C by PyEval_SetTrace Python 3.7.7

Hi.
When I changed frame->f_lasti change de code to back, it's work but the line in 
front code occurs dump, the runtime over.
Example:
I jump to 8 line and after I jump to line 10, it occurs dump.

On python trace pdb the jump works good by the frame-f_lineno.


Att.

Leandro Müller


De: Victor Stinner 
Enviado: segunda-feira, 23 de março de 2020 13:01
Para: Leandro Müller 
Cc: python-dev@python.org 
Assunto: Re: [Python-Dev] Jump on C by PyEval_SetTrace Python 3.7.7

Hi,

It seems like you should be to modify frame->f_lasti in a trace function

FYI in a frame object, the line number is computed using
frame->f_lasti and f->f_code->co_lnotab: PyFrame_GetLineNumber().

See: https://github.com/python/cpython/blob/master/Objects/lnotab_notes.txt

Good luck ;-)

Victor

Le lun. 23 mars 2020 à 00:50, Leandro Müller
 a écrit :
>
> Hi everyone.
>
> I'm trying to make a simple jump on C funcion trace by frame->f_lineno.
> Example is simple, but not working.
>
>
> if (frame->f_lineno == 12){
>
> frame->f_lineno = 8;
>
> }
>
> attached files C and python to run test.
> the line 12 I need to jump to line 8.
>
>
>
> Att.
>
> Leandro Müller
>
> ___
> Python-Dev mailing list -- python-dev@python.org
> To unsubscribe send an email to python-dev-le...@python.org
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python-dev@python.org/message/7RZX4MUF6GLPU4DVXLRTQ534TDRXRL36/
> Code of Conduct: http://python.org/psf/codeofconduct/



--
Night gathers, and now my watch begins. It shall not end until my death.
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/2IYHZ3KU62JAT4MPDWVNUJJASTHCWF36/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 616 -- String methods to remove prefixes and suffixes

2020-03-23 Thread Cameron Simpson

On 22Mar2020 23:33, Rob Cliffe  wrote:
Sorry, another niggle re handling an empty affix:  With your Python 
implementation,

'aba'.cutprefix(('', 'a')) == 'aba'
'aba'.cutsuffix(('', 'a')) == 'ab'
This seems surprising.


That surprises me too. I expect the first matching affix to be used. It 
is the only way for the caller to have a predictable policy.


As a diversion, _are_ there use cases where an empty affix is useful or 
reasonable or likely?


Cheers,
Cameron Simpson 
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/ZL4HWLP7TI3CAKM65WXXGTTTE77A7YSL/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] [RELEASE] Python 3.9.0a5 is now available for testing

2020-03-23 Thread Łukasz Langa
On behalf of the entire Python development community, and the currently serving 
Python release team in particular, I’m pleased to announce the release of 
Python 3.9.0a5. Get it here:

https://www.python.org/downloads/release/python-390a5/ 


This is an early developer preview of Python 3.9

Python 3.9 is still in development. This releasee, 3.9.0a5 is the fifth of six 
planned alpha releases. Alpha releases are intended to make it easier to test 
the current state of new features and bug fixes and to test the release 
process. During the alpha phase, features may be added up until the start of 
the beta phase (2020-05-18) and, if necessary, may be modified or deleted up 
until the release candidate phase (2020-08-10). Please keep in mind that this 
is a preview release and its use is not recommended for production environments.

Major new features of the 3.9 series, compared to 3.8

Many new features for Python 3.9 are still being planned and written. Among the 
new major new features and changes so far:

PEP 584 , Union Operators in dict
PEP 593 , Flexible function and 
variable annotations
PEP 602 , Python adopts a stable 
annual release cadence
BPO 38379 , garbage collection does not 
block on resurrected objects;
BPO 38692 , os.pidfd_open added that allows 
process management without races and signals;
BPO 39926 , Unicode support updated to 
version 13.0.0
BPO 1635741 , when Python is initialized 
multiple times in the same process, it does not leak memory anymore
A number of Python builtins (range, tuple, set, frozenset, list) are now sped 
up using PEP 570  vectorcall
A number of standard library modules (audioop, ast, grp, _hashlib, pwd, 
_posixsubprocess, random, select, struct, termios, zlib) are now using the 
stable ABI defined by PEP 384 .
(Hey, fellow core developer, if a feature you find important is missing from 
this list, let Łukasz know .)
The next pre-release, the last alpha release of Python 3.9, will be 3.9.0a6. It 
is currently scheduled for 2020-04-22. Until then, stay safe!

Your friendly release team,
Ned Deily @nad 
Steve Dower @steve.dower 
Łukasz Langa @ambv ___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/QD7NHTGJ4X5N7GIWZ5UBD74PITIAE64Q/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] MacOS pkg bundles openssl, but doesn't include a cert bundle?

2020-03-23 Thread Matt Billenstein via Python-Dev
Hi, installing the latest 2.7.16 MacOS installer, functions in urllib
will attempt to load trusted certs from:

/Library/Frameworks/Python.framework/Versions/2.7/etc/openssl/cert.pem

But this file is not shipped with the installer package - this makes
urlretrieve and friends fail on https hosts - perhaps the installer
should ship a bundle or enable using something like certifi if it's
installed?

AFAIK Apple has deprecated openssl libs as shipped with the OS a long
time ago and only support their proprietary framework crypto apis and on
MacOS Catalina and newer.

thx

m

-- 
Matt Billenstein
m...@vazor.com
http://www.vazor.com/
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/F4NRIGHUOJVWQAOHJEOOF3AQBB76VNGD/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 616 -- String methods to remove prefixes and suffixes

2020-03-23 Thread Stephen J. Turnbull
Cameron Simpson writes:

 > As a diversion, _are_ there use cases where an empty affix is useful or 
 > reasonable or likely?

In the "raise on failure" design,

"aba".cutsuffix('.doc')

raises,

"aba".cutsuffix('.doc', '')

returns "aba".

BTW, since I'm here, thanks for your discussion of context managers
for loop invariants.  It was very enlightening.
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/DWJSRGHICP6AM6BVPVCQLTA5JOC5IJKO/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: MacOS pkg bundles openssl, but doesn't include a cert bundle?

2020-03-23 Thread Ned Deily
On Mar 23, 2020, at 20:30, Matt Billenstein via Python-Dev 
 wrote:
> Hi, installing the latest 2.7.16 MacOS installer, functions in urllib
> will attempt to load trusted certs from:
> 
> /Library/Frameworks/Python.framework/Versions/2.7/etc/openssl/cert.pem
> 
> But this file is not shipped with the installer package - this makes
> urlretrieve and friends fail on https hosts - perhaps the installer
> should ship a bundle or enable using something like certifi if it's
> installed?

Python 2.7.17 is the most recent 2.7.x release.  You should be using it instead 
of 2.7.16.

When you open one of the current macOS Installer packages from python.org,
the first (Welcome) display includes the following text:

"At the end of this install, click on Install Certificates to install a set of 
current SSL root certificates."

The second display (ReadMe) in the Installer includes the following section:

"Certificate verification and OpenSSL

This package includes its own private copy of OpenSSL 1.0.2.   The trust 
certificates in system and user keychains managed by the Keychain Access 
application and the security command line utility are not used as defaults by 
the Python ssl module.  A sample command script is included in 
/Applications/Python 2.7 to install a curated bundle of default root 
certificates from the third-party certifi package 
(https://pypi.org/project/certifi/).  Double-click on Install Certificates to 
run it.

The bundled pip has its own default certificate store for verifying download 
connections."

By default, a copy of that ReadMe is saved as a file in /Application/Python 
2.7/ should you need to refer to it, along with the "Install 
Certificates.command" file.

We do not currently ship a set of certificates with the installer directly 
because any of them could be replaced or invalidated over the lifetome of the 
installer package.

Hope that helps.


--
  Ned Deily
  n...@python.org -- []
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/52GNL2TCYU3XAXPO4RHGERYQYXEKLNJF/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 616 -- String methods to remove prefixes and suffixes

2020-03-23 Thread Steven D'Aprano
On Sun, Mar 22, 2020 at 10:25:28PM -, Dennis Sweeney wrote:

> Changes:
> - More complete Python implementation to match what the type checking in 
> the C implementation would be
> - Clarified that returning ``self`` is an optimization
> - Added links to past discussions on Python-Ideas and Python-Dev
> - Specified ability to accept a tuple of strings

I am concerned about that tuple of strings feature.

First, an implementation question: you do this when the prefix is a 
tuple:

if isinstance(prefix, tuple):
for option in tuple(prefix):
if not isinstance(option, str):
raise TypeError()
option_str = str(option)

which looks like two unnecessary copies:

1. Having confirmed that `prefix` is a tuple, you call tuple() to 
   make a copy of it in order to iterate over it. Why?

2. Having confirmed that option is a string, you call str() on
   it to (potentially) make a copy. Why?


Aside from those questions about the reference implementation, I am 
concerned about the feature itself. No other string method that returns 
a modified copy of the string takes a tuple of alternatives.

* startswith and endswith do take a tuple of (pre/suff)ixes, but they
  don't return a modified copy; they just return a True or False flag;

* replace does return a modified copy, and only takes a single 
  substring at a time;

* find/index/partition/split etc don't accept multiple substrings 
  to search for.

That makes startswith/endswith the unusual ones, and we should be 
conservative before emulating them.

The difficulty here is that the notion of "cut one of these prefixes" is 
ambiguous if two or more of the prefixes match. It doesn't matter for 
startswith:

"extraordinary".startswith(('ex', 'extra'))

since it is True whether you match left-to-right, shortest-to-largest, 
or even in random order. But for cutprefix, which prefix should be 
deleted?

Of course we can make a ruling by fiat, right now, and declare that it 
will cut the first matching prefix reading left to right, whether that's 
what users expect or not. That seems reasonable when your prefixes are 
hard-coded in the source, as above.

But what happens here?

prefixes = get_prefixes('user.config')
result = mystring.cutprefix(prefixes)

Whatever decision we make -- delete the shortest match, longest match, 
first match, last match -- we're going to surprise and annoy the people 
who expected one of the other behaviours.

This is why replace() still only takes a single substring to match and 
this isn't supported:

"extraordinary".replace(('ex', 'extra'), '')

We ought to get some real-life exposure to the simple case first, before 
adding support for multiple prefixes/suffixes.


-- 
Steven
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/GPXSIDLKTI6WKH5EKJWZEG5KR4AQ6P3J/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 616 -- String methods to remove prefixes and suffixes

2020-03-23 Thread Dennis Sweeney
This should be fixed now.
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/TQQXDLROEKI5ANEF3J7ESFO2VNYRVDYB/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: MacOS pkg bundles openssl, but doesn't include a cert bundle?

2020-03-23 Thread Matt Billenstein via Python-Dev
Thanks Ned - confirmed that works in 2.7.17 - maybe it was there in
2.7.16 and I just overlooked that messaging in the last step.

m

On Mon, Mar 23, 2020 at 09:11:09PM -0400, Ned Deily wrote:
> On Mar 23, 2020, at 20:30, Matt Billenstein via Python-Dev 
>  wrote:
> > Hi, installing the latest 2.7.16 MacOS installer, functions in urllib
> > will attempt to load trusted certs from:
> > 
> > /Library/Frameworks/Python.framework/Versions/2.7/etc/openssl/cert.pem
> > 
> > But this file is not shipped with the installer package - this makes
> > urlretrieve and friends fail on https hosts - perhaps the installer
> > should ship a bundle or enable using something like certifi if it's
> > installed?
> 
> Python 2.7.17 is the most recent 2.7.x release.  You should be using it 
> instead of 2.7.16.
> 
> When you open one of the current macOS Installer packages from python.org,
> the first (Welcome) display includes the following text:
> 
> "At the end of this install, click on Install Certificates to install a set 
> of current SSL root certificates."
> 
> The second display (ReadMe) in the Installer includes the following section:
> 
> "Certificate verification and OpenSSL
> 
> This package includes its own private copy of OpenSSL 1.0.2.   The trust 
> certificates in system and user keychains managed by the Keychain Access 
> application and the security command line utility are not used as defaults by 
> the Python ssl module.  A sample command script is included in 
> /Applications/Python 2.7 to install a curated bundle of default root 
> certificates from the third-party certifi package 
> (https://pypi.org/project/certifi/).  Double-click on Install Certificates to 
> run it.
> 
> The bundled pip has its own default certificate store for verifying download 
> connections."
> 
> By default, a copy of that ReadMe is saved as a file in /Application/Python 
> 2.7/ should you need to refer to it, along with the "Install 
> Certificates.command" file.
> 
> We do not currently ship a set of certificates with the installer directly 
> because any of them could be replaced or invalidated over the lifetome of the 
> installer package.
> 
> Hope that helps.
> 
> 
> --
>   Ned Deily
>   n...@python.org -- []

-- 
Matt Billenstein
m...@vazor.com
http://www.vazor.com/
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/27TF36AURBYJZW2LLGRYGL3GMI6XZZ4W/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 616 -- String methods to remove prefixes and suffixes

2020-03-23 Thread Dennis Sweeney
Steven D'Aprano wrote:
> Having confirmed that prefix is a tuple, you call tuple() to 
> make a copy of it in order to iterate over it. Why?
> 
> Having confirmed that option is a string, you call str() on
> it to (potentially) make a copy. Why?

This was an attempt to ensure no one can do funny business with tuple or str 
subclassing. I was trying to emulate the ``PyTuple_Check`` followed by 
``PyTuple_GET_SIZE`` and ``PyTuple_GET_ITEM`` that are done by the C 
implementation of ``str.startswith()`` to ensure that only the tuple/str 
methods are used, not arbitrary user subclass code. It seems that that's what 
most of the ``str`` methods force.

I was mistaken in how to do this with pure Python. I believe I actually wanted 
something like:

def cutprefix(self, prefix, /):
if not isinstance(self, str):
raise TypeError()

if isinstance(prefix, tuple):
for option in tuple.__iter__(prefix):
if not isinstance(option, str):
raise TypeError()

if str.startswith(self, option):
return str.__getitem__(
self, slice(str.__len__(option), None))

return str.__getitem__(self, slice(None, None))

if not isinstance(prefix, str):
raise TypeError()

if str.startswith(self, prefix):
return str.__getitem__(self, slice(str.__len__(prefix), None))
else:
return str.__getitem__(self, slice(None, None))

... which looks even uglier.

> We ought to get some real-life exposure to the simple case first, before 
> adding support for multiple prefixes/suffixes.

I could be (and have been) convinced either way about whether or not to 
generalize to tuples of strings. I thought Victor made a good point about 
compatibility with ``startswith()``
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/CQVVWGPC454LWATA2Y7BZ5OEAGVSTHEZ/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 616 -- String methods to remove prefixes and suffixes

2020-03-23 Thread Greg Ewing

On 24/03/20 3:43 pm, Dennis Sweeney wrote:

This was an attempt to ensure no one can do funny business with tuple
or str subclassing. I was trying to emulate the ``PyTuple_Check``
followed by ``PyTuple_GET_SIZE`` and ``PyTuple_GET_ITEM`` that are
done by the C implementation of ``str.startswith()``


The C code uses those functions for efficiency, not to prevent
"funny business". PyTuple_GET_SIZE and PyTuple_GET_ITEM are macros
that directly access fields of the tuple struct, and PyTuple_Check
is much faster than a full isinstance check.

There is no point in trying to emulate these in Python code.

--
Greg
___
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/X3OBCBM3XTZD7XFEQ2ULR6XGEXB6PRLZ/
Code of Conduct: http://python.org/psf/codeofconduct/