[Python-Dev] Re: PEP 558: Defined semantics for locals()

2021-07-22 Thread Petr Viktorin




On 21. 07. 21 14:18, Nick Coghlan wrote:

On Mon, 19 Jul 2021 at 21:32, Petr Viktorin  wrote:

The proposal assumes that in the future, ``PyLocals_Get``, and thus
``locals()``, will never gain another kind of return value, however
unlikely that is.
AFAICS, code that uses this will usually check for a single special case
and fall back (or error) for the other(s), so I think it'd be reasonable
to make this an "enum" with two values. e.g.:

int PyLocals_GetReturnBehavior();  # better name?
#define PyLocals_DIRECT_REFERENCE 0
#define PyLocals_SHALLOW_COPY 1


After looking at PyUnicode_Kind, PySendResult, and other already
public enums for inspiration, my proposed spelling is as follows:


typedef enum {
 PyLocals_UNDEFINED = -1;
 PyLocals_DIRECT_REFERENCE = 0,
 PyLocals_SHALLOW_COPY = 1
} PyLocals_Kind;

PyLocals_Kind PyLocals_GetKind(void);
PyLocals_Kind PyFrame_GetLocalsKind(PyFrameObject *);


The PyLocals_UNDEFINED case comes from PyLocals_GetKind() needing an
error value to return when the query API is called with no active
thread state.

I've updated the draft reference implementation to use this API, and
added the associated PEP changes to the review PR at
https://github.com/python/peps/pull/2038/files


Please don't put the enum in the stable ABI. If we would add another 
value and then an older extension would receive it, we'd get undefined 
behavior.

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


[Python-Dev] Re: PEP 558: Defined semantics for locals()

2021-07-22 Thread Nick Coghlan
On Thu, 22 Jul 2021, 6:01 pm Petr Viktorin,  wrote:

>
>
> On 21. 07. 21 14:18, Nick Coghlan wrote:
> > On Mon, 19 Jul 2021 at 21:32, Petr Viktorin  wrote:
> >> The proposal assumes that in the future, ``PyLocals_Get``, and thus
> >> ``locals()``, will never gain another kind of return value, however
> >> unlikely that is.
> >> AFAICS, code that uses this will usually check for a single special case
> >> and fall back (or error) for the other(s), so I think it'd be reasonable
> >> to make this an "enum" with two values. e.g.:
> >>
> >> int PyLocals_GetReturnBehavior();  # better name?
> >> #define PyLocals_DIRECT_REFERENCE 0
> >> #define PyLocals_SHALLOW_COPY 1
> >
> > After looking at PyUnicode_Kind, PySendResult, and other already
> > public enums for inspiration, my proposed spelling is as follows:
> >
> > 
> > typedef enum {
> >  PyLocals_UNDEFINED = -1;
> >  PyLocals_DIRECT_REFERENCE = 0,
> >  PyLocals_SHALLOW_COPY = 1
> > } PyLocals_Kind;
> >
> > PyLocals_Kind PyLocals_GetKind(void);
> > PyLocals_Kind PyFrame_GetLocalsKind(PyFrameObject *);
> > 
> >
> > The PyLocals_UNDEFINED case comes from PyLocals_GetKind() needing an
> > error value to return when the query API is called with no active
> > thread state.
> >
> > I've updated the draft reference implementation to use this API, and
> > added the associated PEP changes to the review PR at
> > https://github.com/python/peps/pull/2038/files
>
> Please don't put the enum in the stable ABI. If we would add another
> value and then an older extension would receive it, we'd get undefined
> behavior.
>

Hmm, I was copying an example that is already in the stable ABI
(PySendResult).

I think it's new in 3.10, though, so it should still be possible to fix
that.

Cheers,
Nick.

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


[Python-Dev] Re: Bug report

2021-07-22 Thread Nick Coghlan
On Thu, 22 Jul 2021, 9:47 am Kyle Stanley,  wrote:

> On Wed, Jul 21, 2021 at 12:19 PM Nguyen Do Minh Duc <
> [email protected]> wrote:
>
>> Hi,
>>
>> When I find what's new in 3.10 beta in
>> https://docs.python.org/whatsnew/3.10.html
>> It redirected me to https://docs.python.org/3/whatsnew/3.10.html which
>> shows 404 error not found nginx. Can you fix this?
>>
>
> Thanks for the report! I don't believe the code and/or config for the web
> server hosting docs.python.org is a public repo (may be mistaken), so
> I'll CC the director of infrastructure, Ee W. Durbin. I suspect they will
> know who to forward this to (or be able to fix it).
>

As far as I know, it's a bulk redirect of otherwise unmatched deep links to
the Python 3 docs, so the OPs link won't work until 3.10 is officially
released.

Until then, only the version specific and dev URLs will work.

Cheers,
Nick.



> Best Regards,
> --
> --Kyle R. Stanley, Python Core Developer (what is a core dev?
> )
> *Pronouns: they/them **(why is my pronoun here?*
> 
> )
>
> ___
> Python-Dev mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-dev.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/WAJM6PFMX2DXOGPEC6I2QATAUT2GNJXC/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
___
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/EMZUUJMCAHH5A3NFVOIFFWXVCNY77LJN/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 558: Defined semantics for locals()

2021-07-22 Thread Ethan Furman

On 7/22/21 1:01 AM, Petr Viktorin wrote:
> On 21. 07. 21 14:18, Nick Coghlan wrote:

>> 
>> typedef enum {
>>  PyLocals_UNDEFINED = -1;
>>  PyLocals_DIRECT_REFERENCE = 0,
>>  PyLocals_SHALLOW_COPY = 1
>> } PyLocals_Kind;
>>
>> PyLocals_Kind PyLocals_GetKind(void);
>> PyLocals_Kind PyFrame_GetLocalsKind(PyFrameObject *);
>> 
>
> Please don't put the enum in the stable ABI. If we would add another value 
and then
> an older extension would receive it, we'd get undefined behavior.

Probably a stupid question, but wouldn't the same thing happen if we didn't use an enum, added another option later, and 
on older extension received that newer value?


--
~Ethan~
___
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/6J5PN5TJ5N3UNJ7UE5UT3NW4CUJ5AGAX/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 558: Defined semantics for locals()

2021-07-22 Thread Petr Viktorin



On 22. 07. 21 15:03, Ethan Furman wrote:

On 7/22/21 1:01 AM, Petr Viktorin wrote:
 > On 21. 07. 21 14:18, Nick Coghlan wrote:

 >> 
 >> typedef enum {
 >>  PyLocals_UNDEFINED = -1;
 >>  PyLocals_DIRECT_REFERENCE = 0,
 >>  PyLocals_SHALLOW_COPY = 1
 >> } PyLocals_Kind;
 >>
 >> PyLocals_Kind PyLocals_GetKind(void);
 >> PyLocals_Kind PyFrame_GetLocalsKind(PyFrameObject *);
 >> 
 >
 > Please don't put the enum in the stable ABI. If we would add another 
value and then

 > an older extension would receive it, we'd get undefined behavior.

Probably a stupid question, but wouldn't the same thing happen if we 
didn't use an enum, added another option later, and on older extension 
received that newer value?


No.
Consider code like:
if (PyLocals_GetKind() == PyLocals_DIRECT_REFERENCE) {
 ...
}
where PyLocals_GetKind() is defined as above, but returns 4.

Technically it's undefined behavior, so the compiler could decide to 
wipe your disk or eat your pets in this case, but that's not very realistic.
More realistically, the compiler is free to only look at the last two 
bits of the value, so 4 will be equivalent to 0, and the comparison will 
be true. There are definitely architestures/compilers that do tricks 
similar to that.


But if PyLocals_GetKind() returns an int, 4 != 0 isn't a problem.
___
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/HFH5MG3LXYEI4YPO3MTDVXTVO7XCUXEA/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Bug report

2021-07-22 Thread Ee Durbin
On Wed, Jul 21, 2021 at 7:45 PM Kyle Stanley  wrote:

> On Wed, Jul 21, 2021 at 12:19 PM Nguyen Do Minh Duc <
> [email protected]> wrote:
>
>> Hi,
>>
>> When I find what's new in 3.10 beta in
>> https://docs.python.org/whatsnew/3.10.html
>> It redirected me to https://docs.python.org/3/whatsnew/3.10.html which
>> shows 404 error not found nginx. Can you fix this?
>>
>
> Thanks for the report! I don't believe the code and/or config for the web
> server hosting docs.python.org is a public repo (may be mistaken), so
> I'll CC the director of infrastructure, Ee W. Durbin. I suspect they will
> know who to forward this to (or be able to fix it).
>

Config that’s responsible for redirects lives at
https://github.com/python/psf-salt/blob/master/salt/docs/config/nginx.docs-backend.conf
if anyone is able to take a look before I’m able to ascertain what’s going
on.

Do we know what the expected behavior is?
___
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/3M4KRVNWXSC56VJK2E7O45DX3UJLBYM5/
Code of Conduct: http://python.org/psf/codeofconduct/