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

Allow arbitrary keywords to @contextmanager functions #68524

Closed
vadmium opened this issue May 31, 2015 · 12 comments
Closed

Allow arbitrary keywords to @contextmanager functions #68524

vadmium opened this issue May 31, 2015 · 12 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@vadmium
Copy link
Member

vadmium commented May 31, 2015

BPO 24336
Nosy @ncoghlan, @ethanfurman, @vadmium, @serhiy-storchaka, @1st1
Files
  • context-kw.patch
  • context-kw.v2.patch
  • context-kw.v3.patch
  • context-kw-2.7.patch: Test only for 2.7
  • 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/serhiy-storchaka'
    closed_at = <Date 2015-06-28.14:13:49.709>
    created_at = <Date 2015-05-31.07:55:38.248>
    labels = ['type-bug', 'library']
    title = 'Allow arbitrary keywords to @contextmanager functions'
    updated_at = <Date 2015-06-28.14:13:49.707>
    user = 'https://github.com/vadmium'

    bugs.python.org fields:

    activity = <Date 2015-06-28.14:13:49.707>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2015-06-28.14:13:49.709>
    closer = 'serhiy.storchaka'
    components = ['Library (Lib)']
    creation = <Date 2015-05-31.07:55:38.248>
    creator = 'martin.panter'
    dependencies = []
    files = ['39571', '39572', '39574', '39577']
    hgrepos = []
    issue_num = 24336
    keywords = ['patch']
    message_count = 12.0
    messages = ['244523', '244526', '244532', '244533', '244539', '244541', '244566', '245858', '245886', '245895', '245904', '245905']
    nosy_count = 7.0
    nosy_names = ['ncoghlan', 'Arfrever', 'ethan.furman', 'python-dev', 'martin.panter', 'serhiy.storchaka', 'yselivanov']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue24336'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5', 'Python 3.6']

    @vadmium
    Copy link
    Member Author

    vadmium commented May 31, 2015

    This patch allows many context managers to accept keyword arguments called “func” and “self”. Current behaviour:

    >>> with TestCase().subTest(func="blaua"): pass
    ... 
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.4/contextlib.py", line 126, in helper
        return _GeneratorContextManager(func, *args, **kwds)
    TypeError: __init__() got multiple values for argument 'func'

    @vadmium vadmium added the type-bug An unexpected behavior, bug, or error label May 31, 2015
    @vadmium
    Copy link
    Member Author

    vadmium commented May 31, 2015

    Sorry here’s a better version that adapts some monkey-patching in the test suite (test_with).

    @serhiy-storchaka serhiy-storchaka added the stdlib Python modules in the Lib dir label May 31, 2015
    @vadmium
    Copy link
    Member Author

    vadmium commented May 31, 2015

    New version with simpler test; thanks Serhiy.

    Looking closer at the history, this actually seems to be a regression caused by revision e4ba097123f6 (bpo-11647). Python 2 is not affected.

    @vadmium
    Copy link
    Member Author

    vadmium commented May 31, 2015

    But maybe it wouldn’t hurt adding the test case in test_contextlib to Python 2.

    @ncoghlan
    Copy link
    Contributor

    The v3 patch looks good to me, and indeed it's a regression I introduced back in 3.2.

    I don't see much value in adding the test to the 2.7 test suite (with contextlib2 just a pip install away, it's very unlikely the standard library version will see any significant updates)

    @serhiy-storchaka
    Copy link
    Member

    LGTM. The patch isn't applied cleanly to 2.7. If you Martin will provide the patch with tests for 2.7, I don't see why not apply it.

    @vadmium
    Copy link
    Member Author

    vadmium commented May 31, 2015

    Here is a patch with just the test case for 2.7, although I don’t have a strong opinion on whether it needs to be added or not.

    @serhiy-storchaka
    Copy link
    Member

    Ping.

    @1st1
    Copy link
    Member

    1st1 commented Jun 27, 2015

    lgtm.. Serhiy, I think you should just commit it.

    @ncoghlan
    Copy link
    Contributor

    My apologies Serhiy, I forgot this was directly assigned to me - all yours now!

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jun 28, 2015

    New changeset f0053d05ed6d by Serhiy Storchaka in branch '3.4':
    Issue bpo-24336: The contextmanager decorator now works with functions with
    https://hg.python.org/cpython/rev/f0053d05ed6d

    New changeset 20aa7083057e by Serhiy Storchaka in branch '3.5':
    Issue bpo-24336: The contextmanager decorator now works with functions with
    https://hg.python.org/cpython/rev/20aa7083057e

    New changeset d4e4bfabc21f by Serhiy Storchaka in branch 'default':
    Issue bpo-24336: The contextmanager decorator now works with functions with
    https://hg.python.org/cpython/rev/d4e4bfabc21f

    New changeset 85c78d4db242 by Serhiy Storchaka in branch '2.7':
    Issue bpo-24336: Backported test for contextmanager. Patch by Martin Panter.
    https://hg.python.org/cpython/rev/85c78d4db242

    @serhiy-storchaka
    Copy link
    Member

    Thank you Martin for your patch.

    @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
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants