Skip to content

Commit 8906919

Browse files
authored
Add hints for most of the intermediate challenges (#74)
1 parent 2e6ef05 commit 8906919

File tree

16 files changed

+29
-3
lines changed

16 files changed

+29
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check out [Awaitable](https://docs.python.org/3.12/library/collections.abc.html#collections.abc.Awaitable).

challenges/intermediate-await/solution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
`run_async` takes an awaitable integer.
55
"""
66

7-
from typing import Awaitable
7+
from collections.abc import Awaitable
88

99

1010
def run_async(func: Awaitable[int]):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check out [Callable](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable).

challenges/intermediate-callable/solution.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Define a callable type that accepts a string argument and returns None.
55
*The parameter name can be arbitrary.*
66
"""
7-
from typing import Callable
7+
from collections.abc import Callable
88

99
SingleStringInput = Callable[[str], None]
1010

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check out [ClassVar](https://docs.python.org/3/library/typing.html#typing.ClassVar).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[TypeVar](https://docs.python.org/3/library/typing.html#typing.TypeVar) and [Callable](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable) are all you need.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Use [TypeVar](https://docs.python.org/3/library/typing.html#typing.TypeVar) to annotate a generic function.
2+
- Or try the ["Generic Functions"](https://docs.python.org/3/reference/compound_stmts.html#generic-functions) statement, it looks like this: `def func[T](arg: T): ...`.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Check out [TypeVar](https://docs.python.org/3/library/typing.html#typing.TypeVar), the `constraints` argument might be a good fit for this challenge.
1+
- [TypeVar](https://docs.python.org/3/library/typing.html#typing.TypeVar) with `constraints` might be a good fit for this challenge.
2+
- You can also try to solve this using the ["Generic Functions"](https://docs.python.org/3/reference/compound_stmts.html#generic-functions) statement.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Annotating an instance variable is the same as annotating a variable, except that you have to put the code in the class body.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check out [Literal](https://docs.python.org/3/library/typing.html#typing.Literal).

0 commit comments

Comments
 (0)