A Possible Bug in Call Policies
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với bản tái hiện pytest_isinstance_issue được liên kết và chạy lần lượt hai tệp pytest riêng lẻ, sau đó chạy toàn bộ test suite. Đọc callpolicies.cpp, overloading.cpp, test_callpolicies.py và test overloading tương ứng để so sánh các lớp Example được export và kết quả của factory. Công việc được xem là hoàn tất khi xác định được liệu Boost.Python, pytest hay Python khiến lớp không đúng được trả về, đồng thời hành vi đó được ghi lại hoặc sửa chữa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hi, I believe I just encountered a possible bug in boost-python...
First of all, the back story, I'm putting together a python-boost based example for my cmaketools project, which makes a cmake-based python package build as straight-forward as possible. I've taken the examples by TNG (who created his examples based off of the official documentation) and turned them into a package with modules with pytest tests. The modules based on his "09-Overloading" example is failing "08-CallPolicies" example in pytest only when they are run together.
Description
When there is a class with the same name but under different a module (in a same package?), return_value_policy<manage_new_object>() call (possibly?) picks a wrong class to instantiate under pytest running 2 test py files each testing one of the classes.
What is peculiar is that it works when only one test file is tested but fails when both are tested together. So, it could be a pytest issue (or Python's for that matter)...
Versions
Boost: 1.71 (official pre-built binary)
Boost Python DLL: boost_python37-vc142-mt-x64-1_71.dll
Python: 3.7.6 (conda)
Compiler: MSVC 2019 (16.6.1)
OS: Window 10
(Near) Minimal Example
Please find the entire example project at https://github.com/hokiedsp/pytest_isinstance_issue. Clone and run the following to reproduce (hopefully)
pip -e .
pytest tests/test_callpolicies.py # passes
pytest tests/test_nor.py # passes
pytest
Last pytest call fails with the assertion error:
def test_callpolicies():
f = policies.Example.factory()
> assert isinstance(f, policies.Example) and str(f) == "factory"
E AssertionError: assert (False)
E + where False = isinstance(<boost_python_example.overloading.Example object at 0x00000202D58B0300>, <class 'boost_python_example.callpolicies.Example'>)
E + where <class 'boost_python_example.callpolicies.Example'> = policies.Example
I'm anticipating f to be boost_python_example.callpolicies.Example but instead boost_python_example.overloading.Example.
Side Note: If CMake cannot find Boost, you need to modify Line 14 of setup.py
configure_opts = ['-DBOOST_ROOT=C:\\Users\\tikum\\AppData\\Local\\Programs\\boost_1_71_0']
code snippets
Here are the sections of most relevant:
callpolicies.cpp
#include <sstream>
#include <string>
class Example {
Example(std::string n) : mName(n) {}
std::string mName;
public:
std::string name() const { return mName; }
static Example* factory()
{
return new Example("factory");
}
// ... snip...
};
#include <boost/python.hpp>
using namespace boost::python;
BOOST_PYTHON_MODULE(callpolicies)
{
class_<Example>("Example", no_init)
.def("__str__", &Example::name)
.def("factory", &Example::factory,
return_value_policy<manage_new_object>())
.staticmethod("factory")
;
}
overloading.cpp
#include <sstream>
#include <string>
class Example {
public:
Example()
{}
// ... snip...
};
#include <boost/python.hpp>
using namespace boost::python;
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(makeIt_overloads, makeIt, 1, 3)
BOOST_PYTHON_MODULE(overloading)
{
void (Example::*d1)() = &Example::doit;
std::string (Example::*d2)(unsigned int) = &Example::doit;
void (Example::*d3)(std::string) = &Example::doit;
class_<Example>("Example")
.def("__str__", &Example::print)
// ...snip...
;
}
test_callpolicies.py
#!/usr/bin/env python
import pytest
from boost_python_example import callpolicies as policies
def test_callpolicies():
# e = callpolicies.Example() # won't work, constructore not available from python
f = policies.Example.factory()
assert isinstance(f, policies.Example) and str(f) == "factory"
- Ngôn ngữ chính
- C++
- Star
- 537
- Fork
- 223
- Merge trung bình
- 11 giờ 22 phút
- Pull request đã merge (30 ngày)
- 2
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của boostorg/python
-
numpy::from_data calls vector::front and crashes (or has UB) when called with a scalar object Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
-
BoostDetectToolset-1.90.0.cmake file not found in an include() call in boost_python-config.cmake Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
Tất cả issue của boostorg/python
Issue tương tự
-
AuTest Bug Tests
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
apache/trafficserver#13714 ·
-
bug build
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
facebookincubator/velox#19143 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
tenstorrent/tt-metal#57393 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
objectionary/eo-graphs#74 ·