mirror of
				https://github.com/python/cpython.git
				synced 2025-11-01 06:01:29 +00:00 
			
		
		
		
	Issue #23671: string.Template now allows to specify the "self" parameter as
keyword argument. string.Formatter now allows to specify the "self" and the "format_string" parameters as keyword arguments.
This commit is contained in:
		
							parent
							
								
									be1eb14241
								
							
						
					
					
						commit
						8ffe917cee
					
				
					 4 changed files with 48 additions and 3 deletions
				
			
		|  | @ -31,6 +31,20 @@ def test_basic_formatter(self): | |||
|         self.assertEqual(fmt.format("foo"), "foo") | ||||
|         self.assertEqual(fmt.format("foo{0}", "bar"), "foobar") | ||||
|         self.assertEqual(fmt.format("foo{1}{0}-{1}", "bar", 6), "foo6bar-6") | ||||
|         self.assertRaises(TypeError, fmt.format) | ||||
|         self.assertRaises(TypeError, string.Formatter.format) | ||||
| 
 | ||||
|     def test_format_keyword_arguments(self): | ||||
|         fmt = string.Formatter() | ||||
|         self.assertEqual(fmt.format("-{arg}-", arg='test'), '-test-') | ||||
|         self.assertRaises(KeyError, fmt.format, "-{arg}-") | ||||
|         self.assertEqual(fmt.format("-{self}-", self='test'), '-test-') | ||||
|         self.assertRaises(KeyError, fmt.format, "-{self}-") | ||||
|         self.assertEqual(fmt.format("-{format_string}-", format_string='test'), | ||||
|                          '-test-') | ||||
|         self.assertRaises(KeyError, fmt.format, "-{format_string}-") | ||||
|         self.assertEqual(fmt.format(arg='test', format_string="-{arg}-"), | ||||
|                          '-test-') | ||||
| 
 | ||||
|     def test_auto_numbering(self): | ||||
|         fmt = string.Formatter() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Serhiy Storchaka
						Serhiy Storchaka