This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author michael.foord
Recipients cjw296, gregory.p.smith, lisroach, mariocj89, michael.foord, sfreilich, xtreak
Date 2019-09-12.11:04:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1568286258.46.0.778939671021.issue36871@roundup.psfhosted.org>
In-reply-to
Content
The code around whether or not to swallow self is hairy. Even if the original spec object is a class we may still be mocking an instance of the class (we don't want users to have to create an instance just to be able to use it as a spec). So we have to carry metadata about whether or not we're mocking an instance. But we also have to support the use case of when users are mocking an actual class object. 

This gets potentially recursive in the case of autospec and has to apply to the class object itself. If we're mocking an instance that is callable then the signature on the top level mock should be taken from __call__. If we're mocking the constructor the signature comes from __init__.

So it's all complicated. And when I originally wrote the code it was worse as it predated inspect.Signature (and was one of the driving use cases for it) and created functions with the right signature by exec'ing code.

So it's better code than it used to be, but I'm still scared of it and that particular bug came in the switch to use sig.bind which I didn't write.
History
Date User Action Args
2019-09-12 11:04:18michael.foordsetrecipients: + michael.foord, gregory.p.smith, cjw296, lisroach, mariocj89, xtreak, sfreilich
2019-09-12 11:04:18michael.foordsetmessageid: <1568286258.46.0.778939671021.issue36871@roundup.psfhosted.org>
2019-09-12 11:04:18michael.foordlinkissue36871 messages
2019-09-12 11:04:18michael.foordcreate