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.

classification
Title: Not so correct error message when giving incorrect type to maxlen in deque
Type: behavior Stage: patch review
Components: Extension Modules Versions: Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: Claudiu.Popa, rhettinger, vajrasky
Priority: low Keywords: patch

Created on 2013-11-25 10:29 by vajrasky, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
fix_error_message_maxlen_deque.patch vajrasky, 2013-11-25 10:29 review
Messages (3)
msg204321 - (view) Author: Vajrasky Kok (vajrasky) * Date: 2013-11-25 10:29
>>> from collections import deque
>>> deque('abc', maxlen='a')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: an integer is required

But it's a lie. You can give None to maxlen
>>> deque('abc', maxlen=None)
deque(['a', 'b', 'c'])

maxlen with None value means unlimited.

You can give boolean value too to maxlen.

>>> deque('abc', maxlen=True)
deque(['c'], maxlen=1)

But since we use boolean and integer interchangeably in Python, so this should not matter in this case.

So, after the patch:
>>> deque('abc', maxlen='a')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: maxlen must be integer or None

Don't worry, I only overrode the TypeError one. So overflow error should be kept intact.

>>> deque('abc', maxlen=2**68)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: Python int too large to convert to C ssize_t

I did not override the negative integer error message, because I assume when people give negative integer, they are in the mindset of giving integer value to maxlen.

>>> deque('abc', maxlen=-3)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: maxlen must be non-negative
msg220577 - (view) Author: PCManticore (Claudiu.Popa) * (Python triager) Date: 2014-06-14 20:12
I believe that returning a TypeError instead of a ValueError is better in this situation. Technically, passing 'a' as maxlen makes that value inappropiate, thus the use of TypeError. It will also be backward compatible. Also, your patch needs test updates.
msg220607 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-06-15 03:17
Sorry, but I don't find this to be an improvement and don't think there is a real problem worth fixing.
History
Date User Action Args
2022-04-11 14:57:54adminsetgithub: 63967
2014-06-15 03:17:23rhettingersetstatus: open -> closed
resolution: rejected
messages: + msg220607
2014-06-15 03:05:01rhettingersetpriority: normal -> low
2014-06-15 03:03:38rhettingersetassignee: rhettinger
2014-06-14 20:12:46Claudiu.Popasetversions: + Python 3.5, - Python 2.7, Python 3.3, Python 3.4
nosy: + Claudiu.Popa

messages: + msg220577

stage: patch review
2013-11-25 10:29:50vajraskycreate