mirror of
				https://github.com/python/cpython.git
				synced 2025-11-04 07:31:38 +00:00 
			
		
		
		
	bpo-35312: Make lib2to3.pgen2.parse.ParseError round-trip pickle-able. (GH-10710)
This commit is contained in:
		
							parent
							
								
									d4f9cf5545
								
							
						
					
					
						commit
						c57e6e2e52
					
				
					 3 changed files with 16 additions and 0 deletions
				
			
		| 
						 | 
					@ -24,6 +24,9 @@ def __init__(self, msg, type, value, context):
 | 
				
			||||||
        self.value = value
 | 
					        self.value = value
 | 
				
			||||||
        self.context = context
 | 
					        self.context = context
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def __reduce__(self):
 | 
				
			||||||
 | 
					        return type(self), (self.msg, self.type, self.value, self.context)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Parser(object):
 | 
					class Parser(object):
 | 
				
			||||||
    """Parser engine.
 | 
					    """Parser engine.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -622,6 +622,18 @@ def test_multiline_str_literals(self):
 | 
				
			||||||
        self.validate(s)
 | 
					        self.validate(s)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class TestPickleableException(unittest.TestCase):
 | 
				
			||||||
 | 
					    def test_ParseError(self):
 | 
				
			||||||
 | 
					        err = ParseError('msg', 2, None, (1, 'context'))
 | 
				
			||||||
 | 
					        for proto in range(pickle.HIGHEST_PROTOCOL + 1):
 | 
				
			||||||
 | 
					            err2 = pickle.loads(pickle.dumps(err, protocol=proto))
 | 
				
			||||||
 | 
					            self.assertEqual(err.args, err2.args)
 | 
				
			||||||
 | 
					            self.assertEqual(err.msg, err2.msg)
 | 
				
			||||||
 | 
					            self.assertEqual(err.type, err2.type)
 | 
				
			||||||
 | 
					            self.assertEqual(err.value, err2.value)
 | 
				
			||||||
 | 
					            self.assertEqual(err.context, err2.context)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def diff_texts(a, b, filename):
 | 
					def diff_texts(a, b, filename):
 | 
				
			||||||
    a = a.splitlines()
 | 
					    a = a.splitlines()
 | 
				
			||||||
    b = b.splitlines()
 | 
					    b = b.splitlines()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1 @@
 | 
				
			||||||
 | 
					Make ``lib2to3.pgen2.parse.ParseError`` round-trip pickle-able.  Patch by Anthony Sottile.
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue