mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	Fix minor subclassing issue with collections.Counter
This commit is contained in:
		
							parent
							
								
									181810b5fe
								
							
						
					
					
						commit
						1c746c28f3
					
				
					 3 changed files with 13 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -459,8 +459,8 @@ def update(self, iterable=None, **kwds):
 | 
			
		|||
            self.update(kwds)
 | 
			
		||||
 | 
			
		||||
    def copy(self):
 | 
			
		||||
        'Like dict.copy() but returns a Counter instance instead of a dict.'
 | 
			
		||||
        return Counter(self)
 | 
			
		||||
        'Return a shallow copy.'
 | 
			
		||||
        return self.__class__(self)
 | 
			
		||||
 | 
			
		||||
    def __reduce__(self):
 | 
			
		||||
        return self.__class__, (dict(self),)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -680,6 +680,15 @@ def test_copying(self):
 | 
			
		|||
            self.assertEqual(len(dup), len(words))
 | 
			
		||||
            self.assertEqual(type(dup), type(words))
 | 
			
		||||
 | 
			
		||||
    def test_copy_subclass(self):
 | 
			
		||||
        class MyCounter(Counter):
 | 
			
		||||
            pass
 | 
			
		||||
        c = MyCounter('slartibartfast')
 | 
			
		||||
        d = c.copy()
 | 
			
		||||
        self.assertEqual(d, c)
 | 
			
		||||
        self.assertEqual(len(d), len(c))
 | 
			
		||||
        self.assertEqual(type(d), type(c))
 | 
			
		||||
 | 
			
		||||
    def test_conversions(self):
 | 
			
		||||
        # Convert to: set, list, dict
 | 
			
		||||
        s = 'she sells sea shells by the sea shore'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -58,6 +58,8 @@ Library
 | 
			
		|||
- Issue #11467: Fix urlparse behavior when handling urls which contains scheme
 | 
			
		||||
  specific part only digits. Patch by Santoso Wijaya.
 | 
			
		||||
 | 
			
		||||
- collections.Counter().copy() now works correctly for subclasses.
 | 
			
		||||
 | 
			
		||||
- Issue #11474: Fix the bug with url2pathname() handling of '/C|/' on Windows.
 | 
			
		||||
  Patch by Santoso Wijaya.
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue