[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-04-28 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: Thanks Avram for the report. I have reopened issue25597. Closing this as the regression change has been reverted for 3.9. -- resolution: -> fixed stage: patch review -> resolved status: open -> closed __

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-04-28 Thread Chris Withers
Chris Withers added the comment: New changeset 521c8d6806adf0305c158d280ec00cca48e8ab22 by Karthikeyan Singaravelan in branch 'master': bpo-39966: Revert "bpo-25597: Ensure wraps' return value is used for magic methods in MagicMock" (GH-19734) https://github.com/python/cpython/commit/521c8d6

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-04-27 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: I opened a PR to revert the change. issue25597 was open for sometime and the implications as reported here seem to be greater than the original report to just call the magicmethod. So we can revert the change to ensure there are no regressions in P

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-04-27 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- pull_requests: +19055 pull_request: https://github.com/python/cpython/pull/19734 ___ Python tracker ___

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-04-27 Thread Avram
Avram added the comment: Checking for presence and then falling through to the <=3.8 behavior as in the patch, seems reasonable. The default magic method behavior presumably comes out of research, trial, and error. If the docs need to be clearer, I think that's different that scrapping the w

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-04-26 Thread Chris Withers
Chris Withers added the comment: I'd go with your instincts on what to do next, I'd have a slight preference to keeping behaviour the same as it was in 3.8 if the changes for 3.9 cause more problems. That leaves us no worse off than we were before, and with the opportunity to improve from th

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-04-22 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: The patch assumed using the magic method attribute as the way to evaluate an object in a context which I got to know is wrong since evaluations in context like boolean are not only dependent on one magic method but has a precedence over several oth

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-04-07 Thread Karthikeyan Singaravelan
Change by Karthikeyan Singaravelan : -- nosy: +serhiy.storchaka ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-03-28 Thread R. David Murray
R. David Murray added the comment: My guess is that it isn't so much that __bool__ is special, as that the evaluation of values in a boolean context is special. What you have to do to make a mock behave "correctly" in the face that I'm not sure (I haven't investigated). And I might be wron

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-03-27 Thread Avram
Avram added the comment: Honestly, I'm not sure if any of the other magic methods behave this way. It would take a little research or someone more familiar with it. Here's more info about how __bool__ behaves. https://docs.python.org/3/reference/datamodel.html#object.__bool__ -- ___

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-03-27 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: Thanks for the example I didn't know hasattr can return False to return a value when the magicmethod was accessed. I will wait for others opinion on this then. -- ___ Python tracker

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-03-27 Thread Avram
Avram added the comment: That is not necessarily the same thing, hence why there was a bug. >>> hasattr(object, '__bool__') False >>> bool(object) True I think you may be right that magic methods shouldn't magically appear for wrapped objects, except those that do magically appear, like __bo

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-03-27 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: > What may make more sense for some magic methods is to call the underlying > object and use the return value or raise any exception that occurs. Sorry, isn't that what the previous issue did? It tries to return the wrapped object attribute and rai

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-03-27 Thread Avram
Avram added the comment: Ah, I see, yes, the documentation is a bit inconsistent. What may make more sense for some magic methods is to call the underlying object and use the return value or raise any exception that occurs. For example: __bool__ return value is bool(mock._mock_wraps) __int__

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-03-27 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: It's supposed to raise an AttributeError if the attribute is not present. The previous case was that magicmethods were not wrapped returning configured values. So this conflicts with the documentation returning a default value when not present inste

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-03-27 Thread Avram
Avram added the comment: They are documented. That said, the subsection section could use a header. https://docs.python.org/3/library/unittest.mock.html#magic-mock Patch looks good! Can't think of any other test scenarios right now. -- ___ Python

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-03-27 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: On thinking more about this the wraps argument provides a way to wrap the calls for the mock to a given object. So when an attribute not present in the wrapped object is being accessed then it should act like the attribute is not present. Falling b

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-03-21 Thread Amir Mohamadi
Change by Amir Mohamadi : -- keywords: +patch pull_requests: +18462 stage: test needed -> patch review pull_request: https://github.com/python/cpython/pull/19102 ___ Python tracker ___

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-03-21 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: Amir, this needs a test like the initial report without preferably using sys.stdout and patch for cases below : 1. Where the attribute is present on the wrapped object and uses it. 2. Where the attribute is not present on the wrapped object and use

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-03-20 Thread Terry J. Reedy
Change by Terry J. Reedy : -- stage: -> test needed ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-03-20 Thread Amir Mohamadi
Amir Mohamadi added the comment: I'd like to work on it. Should I add tests to 'Lib/unittest/test/testmock/testmock.py'?? -- nosy: +Amir ___ Python tracker ___ ___

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-03-15 Thread Karthikeyan Singaravelan
Karthikeyan Singaravelan added the comment: Thanks for the report. There should be a check to ensure that the attribute is present to handle the attribute error while attaching the wrapped object's value. Something like below could be done so that we check for wrapped value or fallback to th

[issue39966] mock 3.9 bug: Wrapped objects without __bool__ raise exception

2020-03-14 Thread Avram
New submission from Avram : This bug was introduced with Issue25597 Here's some code that demonstrates the error: import sys from unittest.mock import patch with patch.object(sys, 'stdout', wraps=sys.stdout) as mockstdout: bool(sys.stdout) This works fine in 3.8 and earl