File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -104,6 +104,10 @@ TEST_SUBMODULE(class_, m) {
104104 ~NoConstructorNew () { print_destroyed (this ); }
105105 };
106106
107+ struct DynamicAttr {
108+ DynamicAttr () = default ;
109+ };
110+
107111 py::class_<NoConstructor>(m, " NoConstructor" )
108112 .def_static (" new_instance" , &NoConstructor::new_instance, " Return an instance" );
109113
@@ -112,6 +116,9 @@ TEST_SUBMODULE(class_, m) {
112116 .def_static (" __new__" ,
113117 [](const py::object &) { return NoConstructorNew::new_instance (); });
114118
119+ py::class_<DynamicAttr>(m, " DynamicAttr" , py::dynamic_attr ())
120+ .def (py::init<>());
121+
115122 // test_pass_unique_ptr
116123 struct ToBeHeldByUniquePtr {};
117124 py::class_<ToBeHeldByUniquePtr, std::unique_ptr<ToBeHeldByUniquePtr>>(m, " ToBeHeldByUniquePtr" )
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3+ import gc
34import sys
45from unittest import mock
56
@@ -45,6 +46,12 @@ def test_instance(msg):
4546 assert cstats .alive () == 0
4647
4748
49+ def test_get_referrers ():
50+ instance = m .DynamicAttr ()
51+ instance .a = "test"
52+ assert instance in gc .get_referrers (instance .__dict__ )
53+
54+
4855def test_instance_new ():
4956 instance = m .NoConstructorNew () # .__new__(m.NoConstructor.__class__)
5057
You can’t perform that action at this time.
0 commit comments