Skip to content

Commit 2e6ef05

Browse files
authored
Add hints for most of the advanced challenge. (#75)
1 parent aebd05a commit 2e6ef05

File tree

15 files changed

+17
-11
lines changed

15 files changed

+17
-11
lines changed

challenges/advanced-buffer/hints.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check out [Buffer](https://docs.python.org/3/library/collections.abc.html#collections.abc.Buffer).
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Check out [Protocol](https://docs.python.org/3/library/typing.html#typing.Protocol), you may need to use a dunder method to define a "callable" type.

challenges/advanced-callable-protocol/question.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
TODO:
33
44
Define a callable type that accepts a string parameter called `name` and returns None.
5-
6-
HINT: Use Protocol
75
"""
86

97

challenges/advanced-callable-protocol/solution.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
TODO:
33
44
Define a callable type that accepts a string parameter called `name` and returns None.
5-
6-
HINT: Use Protocol
75
"""
86
from typing import Protocol
97

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The key is to make `decorator()` return a [Callable](https://docs.python.org/3/library/collections.abc.html#collections.abc.Callable) annotated with a generic type.

challenges/advanced-decorator/solution.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
Define a decorator that wraps a function and returns a function with the same signature.
55
The decorator takes an argument `message` of type string
66
"""
7-
from typing import TypeVar
87
from collections.abc import Callable
8+
from typing import TypeVar
99

1010
# Python < 3.12
1111
#
1212
# T = TypeVar("T", bound=Callable)
1313
#
14-
# def decorator(func: T) -> T:
14+
# def decorator(message: str) -> Callable[[T], T]:
1515
# return func
1616

1717

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- A descriptor's `__get__` method is called in 2 different ways: "owned by class" or "owned by instance", you have to annotate the method for both cases.
2+
- Don't panic, [@overload](https://docs.python.org/3/library/typing.html#typing.overload) can help you with that.

challenges/advanced-descriptor/question.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
TODO:
33
44
Create a descriptor and annotate the __get__ method.
5-
6-
HINT: use typing.overload
75
"""
86

97

challenges/advanced-descriptor/solution.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22
TODO:
33
44
Create a descriptor and annotate the __get__ method.
5-
6-
HINT: use typing.overload
75
"""
86

9-
from typing import overload, Self, Any
7+
from typing import Any, Self, overload
108

119

1210
class Descriptor:

challenges/advanced-forward/hints.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- How about changing that troublesome symbol to a "STRING"?
2+
- Something in the ["\_\_future__"](https://peps.python.org/pep-0563/) may also help you.

0 commit comments

Comments
 (0)