mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Made the 'info' argument to SyntaxError optional, so phase-2 syntax
errors are handled (these gave ``TypeError: not enough arguments''). Also changed its __str__() to correct a typo (missing self.) and return str(self.msg) to ensure the result is always string. Also changed the default __str__ to simply return str(self.args).
This commit is contained in:
		
							parent
							
								
									49bb0e32a0
								
							
						
					
					
						commit
						f394f56c2b
					
				
					 1 changed files with 11 additions and 8 deletions
				
			
		|  | @ -58,10 +58,8 @@ def __init__(self, *args): | |||
|     def __str__(self): | ||||
|         if self.args == None: | ||||
|             return '' | ||||
|         elif type(self.args) == type(''): | ||||
|             return self.args | ||||
| 	else: | ||||
|             return `self.args` | ||||
| 	    return str(self.args) | ||||
| 
 | ||||
|     def __getitem__(self, i): | ||||
| 	if type(self.args) == type(()): | ||||
|  | @ -72,12 +70,17 @@ def __getitem__(self, i): | |||
| 	    raise IndexError | ||||
| 
 | ||||
| class SyntaxError(StandardError): | ||||
|     def __init__(self, msg, info): | ||||
|     filename = lineno = offset = text = None | ||||
|     def __init__(self, msg, info=None): | ||||
|         self.msg = msg | ||||
| 	if info: | ||||
| 	    self.args = msg | ||||
| 	else: | ||||
| 	    self.args = (msg, info) | ||||
| 	if info: | ||||
| 	    self.filename, self.lineno, self.offset, self.text = info | ||||
| 
 | ||||
|     def __str__(self): | ||||
|         return msg | ||||
|         return str(self.msg) | ||||
| 
 | ||||
| 
 | ||||
| class IOError(StandardError): | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Guido van Rossum
						Guido van Rossum