This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author xtreak
Recipients xtreak
Date 2018-06-19.07:54:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1529394867.73.0.56676864532.issue33900@psf.upfronthosting.co.za>
In-reply-to
Content
There was a change made in collections.Counter that made it accept self as the first parameter and hence while doing *args in the method signature args[0] is always set as the self. Hence the check for `not args` becomes a no-op during collection_object.update() calls and the type error is not raised. This is only triggered when it's called as a class method like `Counter.update` and the error message is misleading "descriptor 'update' of 'Counter' object "needs an argument" which says update method of Counter object needs an argument though we are calling the method on class and also calling update on Counter object doesn't need an argument since counter_object.update() works fine as no-op. I think the error message could be improved since argument is not necessary for counter_object.update.

Relevant commit : https://github.com/python/cpython/commit/ae5cb214d2cd41d96943a0ef43a4e95bd9a10b7a#diff-f30cb98704c3ccaf71deaf5503f7f4a1R587
No argument to counter object update test case : https://github.com/python/cpython/blob/ae5cb214d2cd41d96943a0ef43a4e95bd9a10b7a/Lib/test/test_collections.py#L1077
Calling update on Counter class test case : https://github.com/python/cpython/commit/20994f1e27c38973f1854dbdcf9b29fe8e3cd6be#diff-b5f669eab2fa576572b6115caa24427fR928

# Python 3

➜  cpython git:(master) ✗ ./python
Python 3.8.0a0 (heads/bpo33830-httplib-docs-fix-dirty:9bf0fb8, Jun 18 2018, 17:09:54)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from collections import Counter
>>> c = Counter("Hello")


>>> Counter.update()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/user/karthik/cpython/Lib/collections/__init__.py", line 638, in update
    raise TypeError("descriptor 'update' of 'Counter' object "
TypeError: descriptor 'update' of 'Counter' object needs an argument
>>> Counter.update(1) # No error since we check for the first argument to be iterable
>>> c.update() # No args works fine though there was an above error with TypeError: descriptor 'update' of 'Counter' object needs an argument when called on class

>>> Counter.update(1, foo=1) # 1 is considered as self here, a valid counter object works fine and is updated
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/user/karthik/cpython/Lib/collections/__init__.py", line 655, in update
    self.update(kwds)
AttributeError: 'int' object has no attribute 'update'


Thanks
History
Date User Action Args
2018-06-19 07:54:27xtreaksetrecipients: + xtreak
2018-06-19 07:54:27xtreaksetmessageid: <1529394867.73.0.56676864532.issue33900@psf.upfronthosting.co.za>
2018-06-19 07:54:27xtreaklinkissue33900 messages
2018-06-19 07:54:27xtreakcreate