Skip to content

Commit 9408785

Browse files
committed
Python Test for overloaded functions
1 parent 57eecf9 commit 9408785

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed

examples/pure/pure.pyi

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,28 @@ class B(A):
4444

4545
class Incrementer:
4646
@typing.overload
47-
def increment_1(self, x:builtins.int) -> builtins.int: ...
47+
def increment_1(self, x:builtins.int) -> builtins.int:
48+
r"""
49+
And this is for the second comment
50+
"""
4851
@typing.overload
49-
def increment_1(self, x:builtins.float) -> builtins.float: ...
52+
def increment_1(self, x:builtins.float) -> builtins.float:
53+
r"""
54+
This is the original doc comment
55+
"""
5056
def new(self) -> Incrementer: ...
5157

5258
class Incrementer2:
5359
@typing.overload
54-
def increment_2(self, x:builtins.int) -> builtins.int: ...
60+
def increment_2(self, x:builtins.int) -> builtins.int:
61+
r"""
62+
increment_2 for integers, submitted by hands
63+
"""
5564
@typing.overload
56-
def increment_2(self, x:builtins.float) -> builtins.float: ...
65+
def increment_2(self, x:builtins.float) -> builtins.float:
66+
r"""
67+
increment_2 for floats, submitted by hands
68+
"""
5769
def __new__(cls) -> Incrementer2:
5870
r"""
5971
Constructor for Incrementer2
@@ -199,12 +211,15 @@ def overload_example_1(x:builtins.float) -> builtins.float:
199211
"""
200212

201213
@typing.overload
202-
def overload_example_2(x:builtins.int) -> builtins.int: ...
214+
def overload_example_2(x:builtins.int) -> builtins.int:
215+
r"""
216+
Increments integer by 1
217+
"""
203218

204219
@typing.overload
205220
def overload_example_2(x:builtins.float) -> builtins.float:
206221
r"""
207-
Increments float or integer by 1
222+
Increments float by 1
208223
"""
209224

210225
def print_c(c:typing.Optional[builtins.int]=None) -> None: ...

examples/pure/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ submit! {
296296
}],
297297
r#return: || f64::type_output(),
298298
module: None,
299-
doc: "Increments float or integer by 1",
299+
doc: "Increments float by 1",
300300
}
301301
}
302302

@@ -310,7 +310,7 @@ submit! {
310310
}],
311311
r#return: || i64::type_output(),
312312
module: None,
313-
doc: "",
313+
doc: "Increments integer by 1",
314314
}
315315
}
316316

@@ -327,6 +327,7 @@ impl Incrementer {
327327
Incrementer {}
328328
}
329329

330+
/// This is the original doc comment
330331
fn increment_1(&self, x: f64) -> f64 {
331332
x + 1.0
332333
}
@@ -350,7 +351,7 @@ submit! {
350351
],
351352
r#type: MethodType::Instance,
352353
r#return: || i64::type_output(),
353-
doc: "",
354+
doc: "And this is for the second comment",
354355
}
355356
],
356357
}
@@ -392,7 +393,7 @@ submit! {
392393
],
393394
r#type: MethodType::Instance,
394395
r#return: || i64::type_output(),
395-
doc: "",
396+
doc: "increment_2 for integers, submitted by hands",
396397
},
397398
MethodInfo {
398399
name: "__new__",
@@ -412,7 +413,7 @@ submit! {
412413
],
413414
r#type: MethodType::Instance,
414415
r#return: || f64::type_output(),
415-
doc: "",
416+
doc: "increment_2 for floats, submitted by hands",
416417
},
417418
],
418419
}

examples/pure/tests/test_python.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,35 @@ def test_path():
112112

113113
out = echo_path("test")
114114
assert out == pathlib.Path("test")
115+
116+
117+
def test_overload_example_1():
118+
from pure import overload_example_1
119+
120+
assert overload_example_1(1) == 2
121+
assert overload_example_1(1.5) == 2.5
122+
123+
124+
def test_overload_example_2():
125+
from pure import overload_example_2
126+
127+
assert overload_example_2(1) == 2
128+
assert overload_example_2(1.5) == 2.5
129+
130+
131+
def test_overload_incrementer():
132+
from pure import Incrementer
133+
134+
incr = Incrementer()
135+
136+
assert incr.increment_1(1.5) == 2.5
137+
assert incr.increment_1(1) == 2
138+
139+
140+
def test_overload_incrementer_2():
141+
from pure import Incrementer2
142+
143+
incr = Incrementer2()
144+
145+
assert incr.increment_2(1.5) == 2.5
146+
assert incr.increment_2(1) == 2

0 commit comments

Comments
 (0)