[Python-Dev] Re: Using the Python C API in C++

2022-05-03 Thread Antoine Pitrou
On Mon, 2 May 2022 15:21:24 +0200
Victor Stinner  wrote:
> 
> Slowly, more and more tests can be added. For example, this change fixing
> compiler warnings when passing "const PyObject*" to Python C API functions
> adds tests to _testcppext.cpp:
> https://github.com/python/cpython/pull/92138

Doesn't passing "const PyObject*" leak implementation details, for
example that the reference count does not change? It seems to go
counter the objective of making the C API more abstract and more stable.

(C++ has the "mutable" keyword for such situat but I don't think C has
it yet)

Regards

Antoine.


___
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/YFD3WOOR6PRORTTKLTSSOSDNHRYAA2N7/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: Using the Python C API in C++

2022-05-03 Thread Victor Stinner
Hi Antoine,

I'm in favor of making the C API more strict. The limited C API of Python
3.11 no longer cast arguments to PyObject* ! The caller must now cast to
PyObject*: see PEP 670 "convert macros to functions".

Converting macros to static inline functions (PEP 670) is already an
important change. I prefer to not change too many things at the same time.

Maybe in Python 3.12 (or later), we can consider requiring to not pass
"const PyObject*" in C++: remove the cast dropping constness of the
argument.

My long term goal is to only use opaque "PyObject*" "handles" in the C API.
But for practical reasons, changing the C API must be done slowly, step by
step. To reduce the maintenance burden in third party C and C+ extensions.

--

IMO it's a bad idea to use "const PyObject*" in the C API. Maybe today, a
function doesn't modify the memory. But maybe tomorrow, the implementation
will deeply change and will need to modify the memory. In C, using "const"
(for something other than const char*) is just not convenient.

Victor

On Tue, May 3, 2022 at 9:22 AM Antoine Pitrou  wrote:

> On Mon, 2 May 2022 15:21:24 +0200
> Victor Stinner  wrote:
> >
> > Slowly, more and more tests can be added. For example, this change fixing
> > compiler warnings when passing "const PyObject*" to Python C API
> functions
> > adds tests to _testcppext.cpp:
> > https://github.com/python/cpython/pull/92138
>
> Doesn't passing "const PyObject*" leak implementation details, for
> example that the reference count does not change? It seems to go
> counter the objective of making the C API more abstract and more stable.
>
> (C++ has the "mutable" keyword for such situat but I don't think C has
> it yet)
>
> Regards
>
> Antoine.
>
>
> ___
> 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/YFD3WOOR6PRORTTKLTSSOSDNHRYAA2N7/
> 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/S3B2KMUL4OM5CCLTYCFCR5HFZBBFWVKV/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] PEP 690: Lazy Imports

2022-05-03 Thread Germán M . Bravo
Hello,

PEP 690  is now live! It proposes an
exciting new feature to transparently defer the execution of imported
modules until the moment when an imported object is used. Since Python
programs commonly import many more modules than a single invocation of the
program is likely to use in practice, lazy imports can greatly reduce the
overall number of modules loaded, improving startup time and memory usage.

At Meta, we have implemented this feature in Cinder
, and has already demonstrated

startup time improvements up to 70% and memory-use reductions up to 40% on
real-world Python CLIs, while also eliminating the risk for most import
cycles.

Please, don't reply to this message. Feel free to comment or share thoughts
and feedback in Python Discourse
 at
https://discuss.python.org/t/pep-690-lazy-imports.

Best,
Germán

---

Relevant links follow:

https://peps.python.org/pep-0690
https://github.com/facebookincubator/cinder
https://github.com/facebookincubator/cinder/blob/cinder/3.8/CinderDoc/lazy_imports.rst
https://discuss.python.org/t/pep-690-lazy-imports
___
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/IHOSWMIBKCXVB46FI7NGOC2F34RUYZ5Z/
Code of Conduct: http://python.org/psf/codeofconduct/