New submission from Rob Malouf:

Several collections.Counter methods return Counter objects, which is leads to 
wrong or at least confusing behavior when Counter is subclassed.  For example, 
nltk.FreqDist is a subclass of Counter:

>>> x = nltk.FreqDist(['a','a','b','b','b'])
>>> y = nltk.FreqDist(['b','b','b','b','b'])
>>> z = x + y
>>> z.__class__
<class 'collections.Counter'>

This applies to __add__(), __sub__(), __or__(), __and__(), __pos__(), and 
__neg__().  

In contrast, the copy() method does (what I think is) the right thing:

>>> x.copy().__class__
<class 'nltk.probability.FreqDist'>

----------
components: Library (Lib)
messages: 253930
nosy: rmalouf
priority: normal
severity: normal
status: open
title: collections.Counter methods return Counter objects
type: behavior
versions: Python 3.5

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25535>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to