mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Fix bug in Decimal __format__ method that swapped left and right
alignment.
This commit is contained in:
		
							parent
							
								
									8cbe9556cf
								
							
						
					
					
						commit
						b065e52bc2
					
				
					 3 changed files with 11 additions and 2 deletions
				
			
		|  | @ -5551,9 +5551,9 @@ def _format_align(body, spec_dict): | ||||||
| 
 | 
 | ||||||
|     align = spec_dict['align'] |     align = spec_dict['align'] | ||||||
|     if align == '<': |     if align == '<': | ||||||
|         result = padding + sign + body |  | ||||||
|     elif align == '>': |  | ||||||
|         result = sign + body + padding |         result = sign + body + padding | ||||||
|  |     elif align == '>': | ||||||
|  |         result = padding + sign + body | ||||||
|     elif align == '=': |     elif align == '=': | ||||||
|         result = sign + padding + body |         result = sign + padding + body | ||||||
|     else: #align == '^' |     else: #align == '^' | ||||||
|  |  | ||||||
|  | @ -704,6 +704,12 @@ def test_formatting(self): | ||||||
|             ('.0g', '-sNaN', '-sNaN'), |             ('.0g', '-sNaN', '-sNaN'), | ||||||
| 
 | 
 | ||||||
|             ('', '1.00', '1.00'), |             ('', '1.00', '1.00'), | ||||||
|  | 
 | ||||||
|  |             # check alignment | ||||||
|  |             ('<6', '123', '123   '), | ||||||
|  |             ('>6', '123', '   123'), | ||||||
|  |             ('^6', '123', ' 123  '), | ||||||
|  |             ('=+6', '123', '+  123'), | ||||||
|             ] |             ] | ||||||
|         for fmt, d, result in test_values: |         for fmt, d, result in test_values: | ||||||
|             self.assertEqual(format(Decimal(d), fmt), result) |             self.assertEqual(format(Decimal(d), fmt), result) | ||||||
|  |  | ||||||
|  | @ -174,6 +174,9 @@ Core and Builtins | ||||||
| Library | Library | ||||||
| ------- | ------- | ||||||
| 
 | 
 | ||||||
|  | - Fix Decimal.__format__ bug that swapped the meanings of the '<' and | ||||||
|  |   '>' alignment characters. | ||||||
|  | 
 | ||||||
| - Issue #1222: locale.format() bug when the thousands separator is a space | - Issue #1222: locale.format() bug when the thousands separator is a space | ||||||
|   character. |   character. | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Mark Dickinson
						Mark Dickinson