Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not so correct error message when giving incorrect type to maxlen in deque #63967

Closed
vajrasky mannequin opened this issue Nov 25, 2013 · 3 comments
Closed

Not so correct error message when giving incorrect type to maxlen in deque #63967

vajrasky mannequin opened this issue Nov 25, 2013 · 3 comments
Assignees
Labels
extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@vajrasky
Copy link
Mannequin

vajrasky mannequin commented Nov 25, 2013

BPO 19768
Nosy @rhettinger, @PCManticore, @vajrasky
Files
  • fix_error_message_maxlen_deque.patch
  • 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 = <Date 2014-06-15.03:17:23.155>
    created_at = <Date 2013-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 = <Date 2014-06-15.03:17:23.154>
    user = 'https://github.com/vajrasky'

    bugs.python.org fields:

    activity = <Date 2014-06-15.03:17:23.154>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2014-06-15.03:17:23.155>
    closer = 'rhettinger'
    components = ['Extension Modules']
    creation = <Date 2013-11-25.10:29:50.010>
    creator = 'vajrasky'
    dependencies = []
    files = ['32833']
    hgrepos = []
    issue_num = 19768
    keywords = ['patch']
    message_count = 3.0
    messages = ['204321', '220577', '220607']
    nosy_count = 3.0
    nosy_names = ['rhettinger', 'Claudiu.Popa', 'vajrasky']
    pr_nums = []
    priority = 'low'
    resolution = 'rejected'
    stage = 'patch review'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue19768'
    versions = ['Python 3.5']

    @vajrasky
    Copy link
    Mannequin Author

    vajrasky mannequin commented Nov 25, 2013

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

    @vajrasky vajrasky mannequin added extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error labels Nov 25, 2013
    @PCManticore
    Copy link
    Mannequin

    PCManticore mannequin commented Jun 14, 2014

    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.

    @rhettinger rhettinger self-assigned this Jun 15, 2014
    @rhettinger
    Copy link
    Contributor

    Sorry, but I don't find this to be an improvement and don't think there is a real problem worth fixing.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant