[Python-ideas] __before__ and __after__ attributes for functions
Ronald Oussoren
ronaldoussoren at mac.com
Thu Jan 30 09:44:36 CET 2014
On 24 Jan 2014, at 08:54, Suresh V. <suresh_vv at yahoo.com> wrote:
> On Friday 24 January 2014 10:39 AM, Ethan Furman wrote:
>> On 01/23/2014 08:09 PM, Suresh V. wrote:
>>>
>>> Also it would mean that the client code imports from this package.
>>> I would like client code to remain exactly as it is (continue to
>>> import from its original package) but the behavior is enhanced
>>> once this package is imported on startup.
>>
>> /Something/ has to adjust the pre and post conditions -- if not the
>> client code, then what?
>
> pre and post conditions are just one possible use of this.
>
> Going back to my smtplib.SMTP.sendmail example.
> No changes in bulk of client code.
> Single patch module imported in main.
Why is this a good thing? You seem to propose adding a mechanism that makes it easily possible to modify the behaviour of existing functions, which makes it harder to reason about code.
While this is also possible without language changes with the current monkey patching mechanisms its at least clear that your doing something naughty when writing the patching code :-)
Ronald
More information about the Python-ideas
mailing list