-
-
Notifications
You must be signed in to change notification settings - Fork 29.2k
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
Comments
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' |
Sorry here’s a better version that adapts some monkey-patching in the test suite (test_with). |
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. |
But maybe it wouldn’t hurt adding the test case in test_contextlib to Python 2. |
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) |
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. |
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. |
Ping. |
lgtm.. Serhiy, I think you should just commit it. |
My apologies Serhiy, I forgot this was directly assigned to me - all yours now! |
New changeset f0053d05ed6d by Serhiy Storchaka in branch '3.4': New changeset 20aa7083057e by Serhiy Storchaka in branch '3.5': New changeset d4e4bfabc21f by Serhiy Storchaka in branch 'default': New changeset 85c78d4db242 by Serhiy Storchaka in branch '2.7': |
Thank you Martin for your 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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: