mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 11:49:12 +00:00 
			
		
		
		
	Issue22988: clarify yield and exception blocks
This commit is contained in:
		
						commit
						e62430eda4
					
				
					 1 changed files with 5 additions and 4 deletions
				
			
		| 
						 | 
					@ -330,8 +330,9 @@ The execution starts when one of the generator's methods is called.  At that
 | 
				
			||||||
time, the execution proceeds to the first yield expression, where it is
 | 
					time, the execution proceeds to the first yield expression, where it is
 | 
				
			||||||
suspended again, returning the value of :token:`expression_list` to the generator's
 | 
					suspended again, returning the value of :token:`expression_list` to the generator's
 | 
				
			||||||
caller.  By suspended, we mean that all local state is retained, including the
 | 
					caller.  By suspended, we mean that all local state is retained, including the
 | 
				
			||||||
current bindings of local variables, the instruction pointer, and the internal
 | 
					current bindings of local variables, the instruction pointer, the internal
 | 
				
			||||||
evaluation stack.  When the execution is resumed by calling one of the
 | 
					evaluation stack, and the state of any exception handling.  When the execution
 | 
				
			||||||
 | 
					is resumed by calling one of the
 | 
				
			||||||
generator's methods, the function can proceed exactly as if the yield expression
 | 
					generator's methods, the function can proceed exactly as if the yield expression
 | 
				
			||||||
were just another external call.  The value of the yield expression after
 | 
					were just another external call.  The value of the yield expression after
 | 
				
			||||||
resuming depends on the method which resumed the execution.  If
 | 
					resuming depends on the method which resumed the execution.  If
 | 
				
			||||||
| 
						 | 
					@ -348,8 +349,8 @@ suspended.  The only difference is that a generator function cannot control
 | 
				
			||||||
where the execution should continue after it yields; the control is always
 | 
					where the execution should continue after it yields; the control is always
 | 
				
			||||||
transferred to the generator's caller.
 | 
					transferred to the generator's caller.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Yield expressions are allowed in the :keyword:`try` clause of a :keyword:`try`
 | 
					Yield expressions are allowed anywhere in a :keyword:`try` construct.  If the
 | 
				
			||||||
...  :keyword:`finally` construct.  If the generator is not resumed before it is
 | 
					generator is not resumed before it is
 | 
				
			||||||
finalized (by reaching a zero reference count or by being garbage collected),
 | 
					finalized (by reaching a zero reference count or by being garbage collected),
 | 
				
			||||||
the generator-iterator's :meth:`~generator.close` method will be called,
 | 
					the generator-iterator's :meth:`~generator.close` method will be called,
 | 
				
			||||||
allowing any pending :keyword:`finally` clauses to execute.
 | 
					allowing any pending :keyword:`finally` clauses to execute.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue