@@ -109,7 +109,6 @@ class FetchUserProfile(object):
109109 return self ._parse_json(response)
110110
111111 @safe
112- @impure
113112 def _make_request (self , user_id : int ) -> requests.Response:
114113 response = requests.get(' /api/users/{0} ' .format(user_id))
115114 response.raise_for_status()
@@ -148,21 +147,23 @@ that might happen in this particular case:
148147- ` Failure[JsonDecodeException] `
149148
150149And we can work with each of them precisely.
151- It is a good practice to create ` enum ` classes or ` Union ` types
152- with all the possible errors.
150+ It is a good practice to create ` Enum ` classes or ` Union ` types
151+ with a list of all the possible errors.
153152
154153
155154## IO marker
156155
157156But is that all we can improve?
158157Let's look at ` FetchUserProfile ` from another angle.
159- All its methods looks like regular ones:
158+ All its methods look like regular ones:
160159it is impossible to tell whether they are pure or impure from the first sight.
161160
162161It leads to a very important consequence:
163162* we start to mix pure and impure code together* .
163+ We should not do that!
164164
165- And suffer really bad when testing / reusing it.
165+ When these two concepts are mixed
166+ we suffer really bad when testing or reusing it.
166167Almost everything should be pure by default.
167168And we should explicitly mark impure parts of the program.
168169
@@ -194,8 +195,8 @@ class FetchUserProfile(object):
194195
195196 @safe
196197 def _parse_json (
197- self ,
198- io_response : IO [requests.Response],
198+ self ,
199+ io_response : IO [requests.Response],
199200 ) -> IO [' UserProfile' ]:
200201 return io_response.map(lambda response : response.json())
201202```
0 commit comments