You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/rhettinger'closed_at=<Date2014-06-15.03:17:23.155>created_at=<Date2013-11-25.10:29:50.010>labels= ['extension-modules', 'type-bug']
title='Not so correct error message when giving incorrect type to maxlen in deque'updated_at=<Date2014-06-15.03:17:23.154>user='https://github.com/vajrasky'
>>> 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'])
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
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.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: