[issue19768] Not so correct error message when giving incorrect type to maxlen in deque

Vajrasky Kok report at bugs.python.org
Mon Nov 25 11:29:50 CET 2013


New submission from Vajrasky Kok:

>>> 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

----------
components: Extension Modules
files: fix_error_message_maxlen_deque.patch
keywords: patch
messages: 204321
nosy: rhettinger, vajrasky
priority: normal
severity: normal
status: open
title: Not so correct error message when giving incorrect type to maxlen in deque
type: behavior
versions: Python 2.7, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file32833/fix_error_message_maxlen_deque.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19768>
_______________________________________


More information about the Python-bugs-list mailing list