mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	Mark instructions at end of class scope as artificial. (GH-24222)
This commit is contained in:
		
							parent
							
								
									4c94d74152
								
							
						
					
					
						commit
						e56d54e447
					
				
					 2 changed files with 20 additions and 0 deletions
				
			
		| 
						 | 
					@ -956,6 +956,24 @@ def func():
 | 
				
			||||||
             (2, 'line'),
 | 
					             (2, 'line'),
 | 
				
			||||||
             (2, 'return')])
 | 
					             (2, 'return')])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_implicit_return_in_class(self):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        def func():
 | 
				
			||||||
 | 
					            class A:
 | 
				
			||||||
 | 
					                if 3 < 9:
 | 
				
			||||||
 | 
					                    a = 1
 | 
				
			||||||
 | 
					                else:
 | 
				
			||||||
 | 
					                    a = 2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        self.run_and_compare(func,
 | 
				
			||||||
 | 
					            [(0, 'call'),
 | 
				
			||||||
 | 
					             (1, 'line'),
 | 
				
			||||||
 | 
					             (1, 'call'),
 | 
				
			||||||
 | 
					             (1, 'line'),
 | 
				
			||||||
 | 
					             (2, 'line'),
 | 
				
			||||||
 | 
					             (3, 'line'),
 | 
				
			||||||
 | 
					             (3, 'return'),
 | 
				
			||||||
 | 
					             (1, 'return')])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class SkipLineEventsTraceTestCase(TraceTestCase):
 | 
					class SkipLineEventsTraceTestCase(TraceTestCase):
 | 
				
			||||||
    """Repeat the trace tests, but with per-line events skipped"""
 | 
					    """Repeat the trace tests, but with per-line events skipped"""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2371,6 +2371,8 @@ compiler_class(struct compiler *c, stmt_ty s)
 | 
				
			||||||
            compiler_exit_scope(c);
 | 
					            compiler_exit_scope(c);
 | 
				
			||||||
            return 0;
 | 
					            return 0;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        /* The following code is artificial */
 | 
				
			||||||
 | 
					        c->u->u_lineno = -1;
 | 
				
			||||||
        /* Return __classcell__ if it is referenced, otherwise return None */
 | 
					        /* Return __classcell__ if it is referenced, otherwise return None */
 | 
				
			||||||
        if (c->u->u_ste->ste_needs_class_closure) {
 | 
					        if (c->u->u_ste->ste_needs_class_closure) {
 | 
				
			||||||
            /* Store __classcell__ into class namespace & return it */
 | 
					            /* Store __classcell__ into class namespace & return it */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue