[issue22138] patch.object doesn't restore function defaults

2016-01-08 Thread Senthil Kumaran
Senthil Kumaran added the comment: This was an interesting issue. Thanks for the patch, Sean to fix this bug. I have committed it in 3.5 and 3.6. -- assignee: -> orsenthil nosy: +orsenthil resolution: -> fixed stage: commit review -> resolved status: open -> closed versions: +Python

[issue22138] patch.object doesn't restore function defaults

2016-01-08 Thread Roundup Robot
Roundup Robot added the comment: New changeset b67ed559a7d3 by Senthil Kumaran in branch '3.5': Issue #22138: Fix mock.patch behavior when patching descriptors. Restore https://hg.python.org/cpython/rev/b67ed559a7d3 New changeset 9b21dfd71561 by Senthil Kumaran in branch 'default': merge from

[issue22138] patch.object doesn't restore function defaults

2015-12-01 Thread Xiadong Zhu
Xiadong Zhu added the comment: How's the issue going on? The situation to mock function's ``__defaults__`` attribute is general, as default argument is determinate after function definition, when we need to test a function such as: def access_db(statement, backend=default_db_backend):

[issue22138] patch.object doesn't restore function defaults

2015-12-01 Thread Michael Foord
Michael Foord added the comment: Sean's patch looks good to me. -- ___ Python tracker ___ ___

[issue22138] patch.object doesn't restore function defaults

2015-12-01 Thread R. David Murray
Changes by R. David Murray : -- stage: needs patch -> commit review ___ Python tracker ___

[issue22138] patch.object doesn't restore function defaults

2014-08-16 Thread STINNER Victor
Changes by STINNER Victor victor.stin...@gmail.com: -- nosy: +haypo ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22138 ___ ___ Python-bugs-list

[issue22138] patch.object doesn't restore function defaults

2014-08-10 Thread Sean McCully
Sean McCully added the comment: So the changes submitted, take into the attributes that are part of the standard Python Data Model/Descriptors and defined as editable per documentation. https://docs.python.org/3/reference/datamodel.html The thought is if a user is needing to support outside

[issue22138] patch.object doesn't restore function defaults

2014-08-06 Thread Sean McCully
Sean McCully added the comment: Is special casing the special attrs a permament enough solution? -- keywords: +patch nosy: +seanmccully Added file: http://bugs.python.org/file36286/issue22138.patch ___ Python tracker rep...@bugs.python.org

[issue22138] patch.object doesn't restore function defaults

2014-08-06 Thread Ezio Melotti
Ezio Melotti added the comment: Thanks for the patch, however I don't think this is a robust solution. Other objects might have undeletable attributes too. The current code can delete an attribute without restoring it so an easy solution would be removing the hasattr() check, but that seems to

[issue22138] patch.object doesn't restore function defaults

2014-08-06 Thread Michael Foord
Michael Foord added the comment: It might have to be. There's no general purpose solution that will fit every possible behaviour for a Python descriptor I'm afraid. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22138

[issue22138] patch.object doesn't restore function defaults

2014-08-06 Thread Michael Foord
Michael Foord added the comment: And yes, there's deliberate proxy object support in mock.patch (django settings being one specific use-case). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue22138

[issue22138] patch.object doesn't restore function defaults

2014-08-04 Thread Clint Hepner
New submission from Clint Hepner: Following a patch, a function's __defaults__ attribute is reset to None. def foo(x=5): return x assert foo() == 5 # As expected with unittest.mock.patch.object(foo, '__defaults__', (10,)): assert foo() == 10 # As expected

[issue22138] patch.object doesn't restore function defaults

2014-08-04 Thread Ezio Melotti
Ezio Melotti added the comment: The issue seems to affect special attributes that can't be deleted. In Lib/unittest/mock.py:1329, patch() tried to delete the attribute, and then, if it doesn't exist, it restores the previous value. However some special attributes exist even after they are