Skip to content

Commit 39e76d3

Browse files
committed
already submitted change: cl/625564244
1 parent f2903d6 commit 39e76d3

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

clif/python/gen.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -878,8 +878,8 @@ def YieldCheckNullptr(ii):
878878
else:
879879
num_params = n
880880
# extended methods need to include `self` as the first parameter, but
881-
# extended constructors do not.
882-
if func_ast.is_extend_method:
881+
# extended classmethods (and constructors) do not.
882+
if func_ast.is_extend_method and not func_ast.classmethod:
883883
num_params += 1
884884
call_with_params = call + astutils.TupleStr(params[:num_params])
885885
yield I+I+'%s; break;' % call_with_params

clif/testing/python/extend_classmethods.clif

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ from "clif/testing/python/extend_classmethods_clif_aux.h":
2929
@classmethod
3030
def set_static_value(cls, v: int)
3131

32+
@extend
33+
@classmethod
34+
def function_with_defaults(cls, i: int = default,
35+
j: int = default,
36+
k: int = default) -> int
37+
3238
class TestNestedClassmethod:
3339
class Inner:
3440
@extend

clif/testing/python/extend_classmethods_clif_aux.h

+5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ inline void Abc__extend__set_static_value(int v) {
1717
Abc::static_value = v;
1818
}
1919

20+
inline int Abc__extend__function_with_defaults(int i = 3, int j = 5,
21+
int k = 7) {
22+
return (Abc::static_value * i + j) * k;
23+
}
24+
2025
inline int TestNestedClassmethod_Inner__extend__get_static_value() {
2126
return 472;
2227
}

clif/testing/python/extend_classmethods_test.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,27 @@
1919

2020
class ExtendClassmethodsTest(absltest.TestCase):
2121

22+
def setUp(self):
23+
super().setUp()
24+
extend_classmethods.Abc.set_static_value(5432)
25+
2226
def test_create_from_value(self):
2327
expected_value = 543
2428
abc = extend_classmethods.Abc.from_value(expected_value)
2529
self.assertEqual(abc.get_value(), expected_value)
2630

2731
def test_set_class_variable(self):
28-
expected_value = 5432
29-
extend_classmethods.Abc.set_static_value(expected_value)
30-
self.assertEqual(extend_classmethods.Abc.get_static_value(), expected_value)
32+
self.assertEqual(extend_classmethods.Abc.get_static_value(), 5432)
33+
34+
def test_function_with_defaults(self):
35+
fwd = extend_classmethods.Abc.function_with_defaults
36+
self.assertEqual(fwd(), (5432 * 3 + 5) * 7)
37+
self.assertEqual(fwd(2), (5432 * 2 + 5) * 7)
38+
self.assertEqual(fwd(2, 6), (5432 * 2 + 6) * 7)
39+
self.assertEqual(fwd(2, 6, 8), (5432 * 2 + 6) * 8)
40+
self.assertEqual(fwd(i=11), (5432 * 11 + 5) * 7)
41+
self.assertEqual(fwd(j=13), (5432 * 3 + 13) * 7)
42+
self.assertEqual(fwd(k=15), (5432 * 3 + 5) * 15)
3143

3244
def test_nested_classmethod(self):
3345
v = extend_classmethods.TestNestedClassmethod.Inner.get_static_value()

0 commit comments

Comments
 (0)