[Python-Dev] PEP 563: get_type_hints should use closure when available

2021-02-02 Thread Caleb Donovick
The discussion around PEP 649 got me thinking about what I believe is the largest downside to PEP 563: the inability to evaluate annotations created with closures. While this is in general unavoidable, if the type is ever referenced in an annotated function (including as an annotation) it should

[Python-Dev] Re: Understanding "is not safe" in typeobject.c

2021-02-02 Thread Greg Ewing
On 3/02/21 11:05 am, Martin Teichmann wrote:     class MyClass(B, Mixin):           "whatever" this leads to an MRO of MyClass -> B -> Mixin -> A -> object. If you do the tp_new stuff correctly at the C level, you can still create such a class. The only limitation is that if Mixin has a __n

[Python-Dev] Re: PEP 624: Remove Py_UNICODE encoder APIs

2021-02-02 Thread Victor Stinner
On Tue, Feb 2, 2021 at 11:47 PM Inada Naoki wrote: > So if we support add UTF-16 support to ucs2_utf8_encoder(), it means > we need to add code and maintain only for PyUnicode_EncodeUTF8 (encode > from wchar_t* into char*). > > I don't think it is a good deal. As described in the PEP, encoder APIs

[Python-Dev] Re: Understanding "is not safe" in typeobject.c

2021-02-02 Thread Greg Ewing
On 3/02/21 4:52 am, Phil Thompson wrote: Thanks - that's fairly definitive, although I don't really understand why __new__ has this particular requirement. The job of tp_new is to initialise the C struct. To do this, it first has to initialise the fields of the struct it inherits from, then in

[Python-Dev] Re: PEP 624: Remove Py_UNICODE encoder APIs

2021-02-02 Thread Inada Naoki
On Tue, Feb 2, 2021 at 9:40 PM Emily Bowman wrote: > > On Tue, Feb 2, 2021 at 3:47 AM Inada Naoki wrote: >> >> But when wchar_t* is UTF-16, ucs2_utf8_encoder() can not handle >> surrogate escape. >> We need to use a temporary Unicode object. That is what "inefficient" means. > > > Since real UCS-

[Python-Dev] Re: Understanding "is not safe" in typeobject.c

2021-02-02 Thread Martin Teichmann
Hi Phil, Hi List, unfortunately you do not give enough code to reproduce what you are doing, but just guessing roughly: you say that you have a hierarchy like B -> A -> object, with B and A implemented in C, and then want to use B with a mixin. Programmers with a non-python background then often

[Python-Dev] Re: Constructing expected_opinfo_* lists in test_dis.py

2021-02-02 Thread Skip Montanaro
> The problem is not that dis.get_instructions can't be trusted, but that > the test isn't testing the dis module at all. It is testing whether the > output from the compiler has changed. > A lot of the tests in test_dis do that. Thanks. Perhaps such tests belong in a different test_* module? (I a

[Python-Dev] Re: Understanding "is not safe" in typeobject.c

2021-02-02 Thread Phil Thompson via Python-Dev
On 02/02/2021 14:18, Greg Ewing wrote: On 3/02/21 12:07 am, Phil Thompson wrote: On 01/02/2021 23:50, Greg Ewing wrote: At the C level, there is always a *single* inheritance hierarchy. Why? Because a C struct can only extend one other C struct. Yes - I misunderstood what you meant by "at

[Python-Dev] Re: Understanding "is not safe" in typeobject.c

2021-02-02 Thread Greg Ewing
On 3/02/21 12:07 am, Phil Thompson wrote: On 01/02/2021 23:50, Greg Ewing wrote: At the C level, there is always a *single* inheritance hierarchy. Why? Because a C struct can only extend one other C struct. I want my C-implemented class's __new__ to support cooperative multi-inheritance

[Python-Dev] Re: PEP 624: Remove Py_UNICODE encoder APIs

2021-02-02 Thread Emily Bowman
On Tue, Feb 2, 2021 at 3:47 AM Inada Naoki wrote: > But when wchar_t* is UTF-16, ucs2_utf8_encoder() can not handle > surrogate escape. > We need to use a temporary Unicode object. That is what "inefficient" > means. > Since real UCS-2 is effectively dead, maybe it should be flipped around: Make

[Python-Dev] Re: PEP 624: Remove Py_UNICODE encoder APIs

2021-02-02 Thread Inada Naoki
On Tue, Feb 2, 2021 at 7:37 PM M.-A. Lemburg wrote: > > >> That would keep extensions working after a recompile, since > >> Py_UNICODE is already a typedef to wchar_t. > >> > > > > That idea is written in the PEP already. > > https://www.python.org/dev/peps/pep-0624/#replace-py-unicode-with-wchar-

[Python-Dev] PEP 637 - Support for indexing with keyword arguments: request for feedback for SC submission

2021-02-02 Thread Stefano Borini
Hi all, I would like to request feedback by python-dev on the current implementation of PEP 637 - Support for indexing with keyword arguments. https://www.python.org/dev/peps/pep-0637/ The PEP is ready for SC submission and it has a prototype implementation ready, available here (note, not revie

[Python-Dev] Re: PEP 597: Add optional EncodingWarning

2021-02-02 Thread Victor Stinner
On Tue, Feb 2, 2021 at 5:40 AM Inada Naoki wrote: > > In Python 3.10, I added _locale._get_locale_encoding() function which > > is exactly what the encoding used by open() when no encoding is > > specified (encoding=None) and when os.device_encoding(fd) returns > > None. See _Py_GetLocaleEncoding(

[Python-Dev] Re: Understanding "is not safe" in typeobject.c

2021-02-02 Thread Phil Thompson via Python-Dev
On 01/02/2021 19:06, Guido van Rossum wrote: That code is quite old. This comment tries to explain it: ``` /* Check that the use doesn't do something silly and unsafe like object.__new__(dict). To do this, we check that the most derived base that's not a heap type is this type. */ ``` I

[Python-Dev] Re: Understanding "is not safe" in typeobject.c

2021-02-02 Thread Phil Thompson via Python-Dev
On 01/02/2021 23:50, Greg Ewing wrote: On 2/02/21 12:13 am, Phil Thompson via Python-Dev wrote: TypeError: object.__new__(B) is not safe, use B.__new__() It's not safe because object.__new__ doesn't know about any C-level initialisation that A or B need. But A.__new__ is calling object.__new

[Python-Dev] Re: PEP 624: Remove Py_UNICODE encoder APIs

2021-02-02 Thread M.-A. Lemburg
On 02.02.2021 00:33, Inada Naoki wrote: > On Tue, Feb 2, 2021 at 12:43 AM M.-A. Lemburg wrote: >> >> Hi Inada-san, >> >> thank you for adding some comments, but they are not really capturing >> what I think is missing: >> >> """ >> Removing these APIs removes ability to use codec without temporary