Skip to content

Commit 285b28f

Browse files
committed
Fixes docs
1 parent ae3a8e2 commit 285b28f

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ incremental in minor, bugfixes only are patches.
66
See [0Ver](https://0ver.org/).
77

88

9-
## 0.13.0 WIP
9+
## 0.13.0
1010

1111
### Features
1212

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ from django.http import HttpRequest, HttpResponse
132132
from words_app.logic import calculate_points
133133

134134
def view(request: HttpRequest) -> HttpResponse:
135-
user_word: str = request.GET['word'] # just an example
135+
user_word: str = request.POST['word'] # just an example
136136
points = calculate_points(user_word)
137137
... # later you show the result to user somehow
138138

@@ -148,20 +148,20 @@ def _award_points_for_letters(guessed: int) -> int:
148148

149149
Awesome! It works, users are happy, your logic is pure and awesome.
150150
But, later you decide to make the game more fun:
151-
let's make the minimal accoutable letters thresshold
151+
let's make the minimal accoutable letters threshold
152152
configurable for an extra challenge.
153153

154154
You can just do it directly:
155155

156156
```python
157-
def _award_points_for_letters(guessed: int, thresshold: int) -> int:
158-
return 0 if guessed < thresshold else guessed
157+
def _award_points_for_letters(guessed: int, threshold: int) -> int:
158+
return 0 if guessed < threshold else guessed
159159
```
160160

161161
The problem is that `_award_points_for_letters` is deeply nested.
162-
And then you have to pass `thresshold` through the whole callstack,
162+
And then you have to pass `threshold` through the whole callstack,
163163
including `calculate_points` and all other functions that might be on the way.
164-
All of them will have to accept `thresshold` as a parameter!
164+
All of them will have to accept `threshold` as a parameter!
165165
This is not useful at all!
166166
Large code bases will struggle a lot from this change.
167167

@@ -177,7 +177,7 @@ from django.http import HttpRequest, HttpResponse
177177
from words_app.logic import calculate_points
178178

179179
def view(request: HttpRequest) -> HttpResponse:
180-
user_word: str = request.GET['word'] # just an example
180+
user_word: str = request.POST['word'] # just an example
181181
points = calculate_points(user_words)(settings) # passing the dependencies
182182
... # later you show the result to user somehow
183183

@@ -187,15 +187,15 @@ from typing_extensions import Protocol
187187
from returns.context import RequiresContext
188188

189189
class _Deps(Protocol): # we rely on abstractions, not direct values or types
190-
WORD_THRESSHOLD: int
190+
WORD_THRESHOLD: int
191191

192192
def calculate_points(word: str) -> RequiresContext[_Deps, int]:
193193
guessed_letters_count = len([letter for letter in word if letter != '.'])
194194
return _award_points_for_letters(guessed_letters_count)
195195

196196
def _award_points_for_letters(guessed: int) -> RequiresContext[_Deps, int]:
197197
return RequiresContext(
198-
lambda deps: 0 if guessed < deps.WORD_THRESSHOLD else guessed,
198+
lambda deps: 0 if guessed < deps.WORD_THRESHOLD else guessed,
199199
)
200200
```
201201

docs/pages/context.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ for each guessed letter in a word (unguessed letters are marked as ``'.'``):
3838
from words_app.logic import calculate_points
3939
4040
def view(request: HttpRequest) -> HttpResponse:
41-
user_word: str = request.GET['word'] # just an example
41+
user_word: str = request.POST['word'] # just an example
4242
points = calculate_points(user_word)
4343
... # later you show the result to user somehow
4444
@@ -59,15 +59,15 @@ Adding configuration
5959
~~~~~~~~~~~~~~~~~~~~
6060

6161
But, later you decide to make the game more fun:
62-
let's make the minimal accoutable letters thresshold
62+
let's make the minimal accoutable letters threshold
6363
configurable for an extra challenge.
6464

6565
You can just do it directly:
6666

6767
.. code:: python
6868
69-
def _award_points_for_letters(guessed: int, thresshold: int) -> int:
70-
return 0 if guessed < thresshold else guessed
69+
def _award_points_for_letters(guessed: int, threshold: int) -> int:
70+
return 0 if guessed < threshold else guessed
7171
7272
And now your code won't simply type-check.
7373
Because that's how our caller looks like:
@@ -80,7 +80,7 @@ Because that's how our caller looks like:
8080
8181
To fix this ``calculate_points`` function
8282
(and all other upper caller functions)
83-
will have to accept ``thresshold: int``
83+
will have to accept ``threshold: int``
8484
as a parameter and pass it to ``_award_points_for_letters``.
8585

8686
Imagine that your large project has multiple
@@ -111,7 +111,7 @@ Let's see how our code changes:
111111
from words_app.logic import calculate_points
112112
113113
def view(request: HttpRequest) -> HttpResponse:
114-
user_word: str = request.GET['word'] # just an example
114+
user_word: str = request.POST['word'] # just an example
115115
points = calculate_points(user_words)(settings) # passing the dependencies
116116
... # later you show the result to user somehow
117117
@@ -123,15 +123,15 @@ Let's see how our code changes:
123123
from returns.context import RequiresContext
124124
125125
class _Deps(Protocol): # we rely on abstractions, not direct values or types
126-
WORD_THRESSHOLD: int
126+
WORD_THRESHOLD: int
127127
128128
def calculate_points(word: str) -> RequiresContext[_Deps, int]:
129129
guessed_letters_count = len([letter for letter in word if letter != '.'])
130130
return _award_points_for_letters(guessed_letters_count)
131131
132132
def _award_points_for_letters(guessed: int) -> RequiresContext[_Deps, int]:
133133
return RequiresContext(
134-
lambda deps: 0 if guessed < deps.WORD_THRESSHOLD else guessed,
134+
lambda deps: 0 if guessed < deps.WORD_THRESHOLD else guessed,
135135
)
136136
137137
And now you can pass your dependencies in a really direct and explicit way.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ style = "https://raw.githubusercontent.com/wemake-services/wemake-python-stylegu
99

1010
[tool.poetry]
1111
name = "returns"
12-
version = "0.12.0"
12+
version = "0.13.0"
1313
description = "Make your functions return something meaningful, typed, and safe!"
1414
license = "BSD-3-Clause"
1515

0 commit comments

Comments
 (0)