Navigation Menu

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

functools.singledispatch: Misleading exception when calling without arguments #78148

Closed
doerwalter opened this issue Jun 26, 2018 · 14 comments
Closed
Labels
3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@doerwalter
Copy link
Contributor

BPO 33967
Nosy @doerwalter, @vstinner, @methane, @serhiy-storchaka, @corona10, @ZackerySpytz, @miss-islington
PRs
  • bpo-33967: singledispatch raises TypeError when no positional arguments #8184
  • [3.7] bpo-33967: Fix singledispatch raised IndexError when no args (GH-8184) #8220
  • [3.6] bpo-33967: Fix singledispatch raised IndexError when no args (GH-8184) #8221
  • bpo-33967: Remove use of deprecated assertRaisesRegexp() #8261
  • [3.6] bpo-33967: Remove use of deprecated assertRaisesRegexp() (GH-8261) #8295
  • [3.7] bpo-33967: Remove use of deprecated assertRaisesRegexp() (GH-8261) #8296
  • bpo-33967: Fix wrong use of assertRaises #8306
  • bpo-33967: Fix wrong use of assertRaises #8306
  • [3.7] bpo-33967: Fix wrong use of assertRaises (GH-8306) #8308
  • [3.6] bpo-33967: Fix wrong use of assertRaises (GH-8306) #8309
  • 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 = None
    closed_at = <Date 2018-07-17.06:20:39.742>
    created_at = <Date 2018-06-26.11:57:10.842>
    labels = ['3.7', '3.8', 'type-bug', 'library']
    title = 'functools.singledispatch: Misleading exception when calling without arguments'
    updated_at = <Date 2018-07-17.06:20:39.741>
    user = 'https://github.com/doerwalter'

    bugs.python.org fields:

    activity = <Date 2018-07-17.06:20:39.741>
    actor = 'methane'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-07-17.06:20:39.742>
    closer = 'methane'
    components = ['Library (Lib)']
    creation = <Date 2018-06-26.11:57:10.842>
    creator = 'doerwalter'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 33967
    keywords = ['patch']
    message_count = 14.0
    messages = ['320485', '321259', '321313', '321359', '321363', '321365', '321512', '321514', '321725', '321727', '321743', '321789', '321792', '321794']
    nosy_count = 7.0
    nosy_names = ['doerwalter', 'vstinner', 'methane', 'serhiy.storchaka', 'corona10', 'ZackerySpytz', 'miss-islington']
    pr_nums = ['8184', '8220', '8221', '8261', '8295', '8296', '8306', '8306', '8308', '8309']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue33967'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    @doerwalter
    Copy link
    Contributor Author

    When I call a function decorated with functools.singledispatch without an argument, I get the following:

    $ python
    Python 3.6.5 (default, Jun 17 2018, 12:13:06)
    [GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import functools
    >>> @functools.singledispatch
    ... def f(x):
    ...     pass
    ...
    >>> f()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/functools.py", line 803, in wrapper
        return dispatch(args[0].__class__)(*args, **kw)
    IndexError: tuple index out of range

    I would have expected a TypeError along the lines of

    TypeError: f() missing 1 required positional argument: 'x'

    @doerwalter doerwalter added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jun 26, 2018
    @corona10
    Copy link
    Member

    corona10 commented Jul 8, 2018

    @doerwalter

    Can I take a look this issue?

    @methane
    Copy link
    Member

    methane commented Jul 9, 2018

    Signature mismatch should raise TypeError, not IndexError.
    I think this should be backported to 3.6 and 3.7.

    @methane methane added 3.7 (EOL) end of life 3.8 only security fixes labels Jul 9, 2018
    @methane
    Copy link
    Member

    methane commented Jul 10, 2018

    New changeset 445f1b3 by INADA Naoki (Dong-hee Na) in branch 'master':
    bpo-33967: Fix singledispatch raised IndexError when no args (GH-8184)
    445f1b3

    @miss-islington
    Copy link
    Contributor

    New changeset df9f633 by Miss Islington (bot) in branch '3.7':
    bpo-33967: Fix singledispatch raised IndexError when no args (GH-8184)
    df9f633

    @methane methane closed this as completed Jul 10, 2018
    @miss-islington
    Copy link
    Contributor

    New changeset 6ceab46 by Miss Islington (bot) in branch '3.6':
    bpo-33967: Fix singledispatch raised IndexError when no args (GH-8184)
    6ceab46

    @ZackerySpytz
    Copy link
    Mannequin

    ZackerySpytz mannequin commented Jul 12, 2018

    The test added in this change uses the deprecated method assertRaisesRegexp(), so -Werror will cause test_functools to fail. PR 8261 fixes this.

    @methane
    Copy link
    Member

    methane commented Jul 12, 2018

    New changeset 9e9b2c3 by INADA Naoki (Zackery Spytz) in branch 'master':
    bpo-33967: Remove use of deprecated assertRaisesRegexp() (GH-8261)
    9e9b2c3

    @vstinner
    Copy link
    Member

    New changeset 336c953 by Victor Stinner (Miss Islington (bot)) in branch '3.6':
    bpo-33967: Remove use of deprecated assertRaisesRegexp() (GH-8261) (GH-8295)
    336c953

    @vstinner
    Copy link
    Member

    New changeset 0a820a2 by Victor Stinner (Miss Islington (bot)) in branch '3.7':
    bpo-33967: Remove use of deprecated assertRaisesRegexp() (GH-8261) (GH-8296)
    0a820a2

    @serhiy-storchaka
    Copy link
    Member

    The purpose of using assertRaisesRegexp() was testing the error message. assertRaises() doesn't do this. Needed to restore the appropriate assertion method, but using a non-deprecated alias: assertRaisesRegex().

    @methane
    Copy link
    Member

    methane commented Jul 17, 2018

    New changeset 56d8f57 by INADA Naoki in branch 'master':
    bpo-33967: Fix wrong use of assertRaises (GH-8306)
    56d8f57

    @miss-islington
    Copy link
    Contributor

    New changeset 892df9d by Miss Islington (bot) in branch '3.7':
    bpo-33967: Fix wrong use of assertRaises (GH-8306)
    892df9d

    @miss-islington
    Copy link
    Contributor

    New changeset 8b5d191 by Miss Islington (bot) in branch '3.6':
    bpo-33967: Fix wrong use of assertRaises (GH-8306)
    8b5d191

    @methane methane closed this as completed Jul 17, 2018
    @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
    3.7 (EOL) end of life 3.8 only security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    6 participants