[BUG] def_property_readonly_static calling PyErr_WarnEx fails on PyPy
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
Issue description
When calling PyErr_WarnEx from inside the lambda given to def_property_static_readonly, it fails with KeyError, but only when run under PyPy.
Perhaps this is a PyPy bug, but I don't really know where I'd start debugging that.
PyPy 7.3.5, pybind11 2.6.2, gcc 9.3.0.
Reproducible example code
#include <pybind11/pybind11.h>
namespace py = pybind11;
void deprecation_warning(const char *msg)
{
if (PyErr_WarnEx(PyExc_DeprecationWarning, msg, 1) == -1)
throw py::error_already_set();
}
class A
{
};
PYBIND11_MODULE(pybind11_property, m) {
py::class_<A>(m, "A")
.def_property_readonly_static("FOO",
[](py::object) {
deprecation_warning("FOO is deprecated");
return 3;
}
)
;
}
When run with python -c 'from pybind11_property import A; A.FOO' I get
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<string>", line 4, in __get__
KeyError: '__builtins__'
In case it's useful, here are the pyproject.toml and setup.py I'm using to install the module (with pip install -e .):
[build-system]
requires = ["setuptools", "wheel", "pybind11==2.6.2"]
#!/usr/bin/env python
from setuptools import setup
from pybind11.setup_helpers import Pybind11Extension
setup(
name='pybind11_property',
version='0.1',
ext_modules=[Pybind11Extension(
name='pybind11_property',
sources=['property.cpp'])]
)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the reproducible property.cpp example and the pybind11 def_property_readonly_static entry point. Run the example under the stated PyPy 7.3.5 and pybind11 2.6.2 versions, then compare the PyErr_WarnEx path with the failing KeyError traceback. Done means identifying and resolving the PyPy-specific failure with a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100