[issue33900] collections.counter update method without argument gives misleading error

2018-06-19 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Okay, got it. Sorry for the noise. Closing it.

Thanks

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33900] collections.counter update method without argument gives misleading error

2018-06-19 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

This error is correct. It is the same as for dict.update.

>>> dict.update()
Traceback (most recent call last):
  File "", line 1, in 
TypeError: descriptor 'update' of 'dict' object needs an argument

Perhaps you missed the difference between a descriptor and a method.

--
nosy: +rhettinger, serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue33900] collections.counter update method without argument gives misleading error

2018-06-19 Thread Karthikeyan Singaravelan

New submission from Karthikeyan Singaravelan :

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 "", line 1, in 
  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 "", line 1, in 
  File "/user/karthik/cpython/Lib/collections/__init__.py", line 655, in update
self.update(kwds)
AttributeError: 'int' object has no attribute 'update'


Thanks

--
components: Library (Lib)
messages: 319935
nosy: xtreak
priority: normal
severity: normal
status: open
title: collections.counter update method without argument gives misleading error
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com