Skip to content

Commit 4e0599c

Browse files
committed
Slight improvement to Python typing
1 parent 9bf9e9a commit 4e0599c

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

tools/adventure-pack/goodies/python3/int.digits/__init__.py renamed to tools/adventure-pack/goodies/python3/int_digits/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
def set_up_adventure_pack():
2-
def digits(self: int, radix: int = 10):
1+
from typing import Generator
2+
3+
4+
def set_up_adventure_pack() -> None:
5+
def digits(self: int, radix: int = 10) -> Generator[int, None, None]:
36
if self < 0:
47
raise ValueError("Must invoke on a non-negative integer.")
58

tools/adventure-pack/goodies/python3/int.digits/test.py renamed to tools/adventure-pack/goodies/python3/int_digits/test.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import os
1+
import int_digits
22

3-
with open(os.path.join(os.path.dirname(__file__), "__init__.py"), "r") as f:
4-
module_code = f.read()
5-
exec(module_code)
63

7-
8-
def test_base_10():
4+
def test_base_10() -> None:
95
assert list((123).digits(10)) == [3, 2, 1]
106
assert list((1337).digits(10)) == [7, 3, 3, 1]
117
assert list((42).digits(10)) == [2, 4]
@@ -29,7 +25,7 @@ def test_base_10():
2925
assert list((5).digits(10)) == [5]
3026

3127

32-
def test_base_2():
28+
def test_base_2() -> None:
3329
assert list((12).digits(2)) == [0, 0, 1, 1]
3430
assert list((2**10 - 1).digits(2)) == [1] * 10
3531
assert list((2**30).digits(2)) == ([0] * 30 + [1])

tools/adventure-pack/src/app/__tests__/__snapshots__/equip-test.ts.snap

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -867,13 +867,16 @@ fun lcm(a: Int, b: Int): Int = a / gcd(a, b) * b
867867
/////////////////////////// END ADVENTURE PACK CODE ////////////////////////////"
868868
`;
869869
870-
exports[`App can equip single goody: Python 3 int.digits 1`] = `
870+
exports[`App can equip single goody: Python 3 int_digits 1`] = `
871871
"########################## BEGIN ADVENTURE PACK CODE ###########################
872872
# Adventure Pack commit fake-commit-hash
873873
# Running at: https://example.com/
874874
875-
def set_up_adventure_pack():
876-
def digits(self: int, radix: int = 10):
875+
from typing import Generator
876+
877+
878+
def set_up_adventure_pack() -> None:
879+
def digits(self: int, radix: int = 10) -> Generator[int, None, None]:
877880
if self < 0:
878881
raise ValueError("Must invoke on a non-negative integer.")
879882

tools/adventure-pack/src/app/__tests__/__snapshots__/render-test.ts.snap

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,9 +530,12 @@ import gcd_int_int.gcd
530530
fun lcm(a: Int, b: Int): Int = a / gcd(a, b) * b"
531531
`;
532532
533-
exports[`App can render goody: Python 3 int.digits 1`] = `
534-
"def set_up_adventure_pack():
535-
def digits(self: int, radix: int = 10):
533+
exports[`App can render goody: Python 3 int_digits 1`] = `
534+
"from typing import Generator
535+
536+
537+
def set_up_adventure_pack() -> None:
538+
def digits(self: int, radix: int = 10) -> Generator[int, None, None]:
536539
if self < 0:
537540
raise ValueError("Must invoke on a non-negative integer.")
538541

0 commit comments

Comments
 (0)