Skip to content

Commit 874ea83

Browse files
Евгений БлиновЕвгений Блинов
authored andcommitted
Add usage note for yield_from_it replacement
1 parent 9fc6d9e commit 874ea83

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,22 @@ There are 2 main difficulties in developing typing here:
310310
- We mix several types of syntax in a single template function, but the static analyzer does not know that this is a template and part of the code will be deleted from here. In its opinion, this is the final function that will continue to be used in your project.
311311

312312
As you can see, typing in Python is not well suited for metaprogramming. However, in this project, almost all the problems with typing turned out to be solved in one way or another. The main reason why this is so is that we mostly *remove* code from functions, but hardly *add* it there during code generation. In other words, we almost never encounter the problem of how to type the *added* code. This makes the solution to most typing problems accessible. However! Unfortunately, we were not able to completely hide all the typing problems under the hood, but you should still be aware of some of them if you use `mypy` or another analyzer.
313+
314+
If you use the keyword `yield from`, you need to call the function `yield_from_it` instead:
315+
316+
```python
317+
from transfunctions import yield_it
318+
319+
@superfunction
320+
def my_superfunction():
321+
print('so, ', end='')
322+
with sync_context:
323+
print("it's just usual function!")
324+
with async_context:
325+
print("it's an async function!")
326+
with generator_context:
327+
print("it's a generator function!")
328+
yield_from_it([1, 2, 3])
329+
```
330+
331+
The keywords yield or yield from are available to you and work perfectly, but from the point of view of a static type checker, they turn the function into a generator, which should also mean a special type annotation. By replacing this fragment with a function call, we hack it.

0 commit comments

Comments
 (0)