Skip to content

Commit 2e3d29d

Browse files
committed
Update classmethod with reviewer comments
1 parent e5f8666 commit 2e3d29d

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

tests/test_class.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ TEST_SUBMODULE(class_, m) {
6464
py::class_<NoConstructor>(m, "NoConstructor")
6565
.def_static("new_instance", &NoConstructor::new_instance, "Return an instance")
6666
.def_classmethod(
67-
"new_instance_uuid",
68-
[](py::object &cls) {
69-
py::int_ uuid = getattr(cls, "uuid", py::int_(0));
70-
cls.attr("uuid") = uuid + py::int_(1);
67+
"new_instance_seq_id",
68+
[](py::type &cls) {
69+
py::int_ seq_id = getattr(cls, "seq_id", py::int_(0));
70+
cls.attr("seq_id") = seq_id + py::int_(1);
7171
return NoConstructorNew::new_instance();
7272
},
73-
"Returns a new instance and then increment the uuid");
73+
"Returns a new instance and then increment the seq_id");
7474

7575
py::class_<NoConstructorNew>(m, "NoConstructorNew")
7676
.def(py::init([](const NoConstructorNew &self) { return self; })) // Need a NOOP __init__

tests/test_class.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ def test_instance_new(msg):
3232

3333

3434
def test_classmethod(num_instances=10):
35+
assert not hasattr(m.NoConstructor, "seq_id")
3536
for i in range(num_instances):
36-
assert getattr(m.NoConstructor, "uuid", 0) == i
37-
m.NoConstructor.new_instance_uuid()
37+
m.NoConstructor.new_instance_seq_id()
38+
assert m.NoConstructor.seq_id == i + 1
3839

3940

4041
def test_type():

0 commit comments

Comments
 (0)