Skip to content

Commit

Permalink
Improve the question of advanced-typeguard, fixed #99
Browse files Browse the repository at this point in the history
  • Loading branch information
laike9m committed Jan 23, 2024
1 parent ebd195a commit 0fa2d80
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
8 changes: 3 additions & 5 deletions challenges/advanced-typeguard/question.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
"""
TODO:
is_string is a function that takes an argument value of arbitrary type, and returns a boolean.
You should make is_string be able to narrow the type of the argument based on its return value:
when it's true, narrow value's type to str.
Basically, it should work like `isinstance(value, str)` from the perspective of a type checker.
`is_string` determines whether the input value is a string.
Your job is to make the type checker be aware of this information.
"""
from typing import Any


def is_string(value: Any):
...
return isinstance(value, str)


## End of your code ##
Expand Down
6 changes: 2 additions & 4 deletions challenges/advanced-typeguard/solution.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
"""
TODO:
is_string is a function that takes an argument value of arbitrary type, and returns a boolean.
You should make is_string be able to narrow the type of the argument based on its return value:
when it's true, narrow value's type to str.
Basically, it should work like `isinstance(value, str)` from the perspective of a type checker.
`is_string` determines whether the input value is a string.
Your job is to make the type checker be aware of this information.
"""
from typing import Any, TypeGuard

Expand Down
4 changes: 2 additions & 2 deletions challenges/extreme-self-casting/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from typing import Callable, Concatenate, Generic, ParamSpec, TypeVar


R = TypeVar('R')
P = ParamSpec('P')
R = TypeVar("R")
P = ParamSpec("P")


class Fn(Generic[R, P]):
Expand Down

0 comments on commit 0fa2d80

Please sign in to comment.