Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95306

Re: Hooking Mechanism when Entering and Leaving a Try Block

Date 2015-08-12 20:44 +0200
From "Sven R. Kunze" <srkunze@mail.de>
Subject Re: Hooking Mechanism when Entering and Leaving a Try Block
References <55CA6D7F.1060705@mail.de> <CALwzidkBoDo1TZj2CWfimYtagtArN9r9dvw1Ke9HqcthdipV4Q@mail.gmail.com> <55CB6EAC.5040004@mail.de> <CAPTjJmoqg9sA-QB3RoRPQFx1osOYyBzff-UX8f2zrzxWpt7sYQ@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.132.1439405104.3627.python-list@python.org> (permalink)

Show all headers | View raw


On 12.08.2015 18:11, Chris Angelico wrote:
> On Thu, Aug 13, 2015 at 2:05 AM, Sven R. Kunze <srkunze@mail.de> wrote:
>> Unfortunately, no. :(
>>
>> It should work out of the box with no "let me replace all my try-except
>> statements in my 10 million line code base".
> (Please don't top-post.)

Is this some guideline? I actually quite dislike pick somebody's mail to 
pieces. It actually pulls things out of context. But if this is a rule 
for this, so be it.

> Sounds to me like you want some sort of AST transform, possibly in an
> import hook. Check out something like MacroPy for an idea of how
> powerful this sort of thing can be.

Sounds like I MacroPy would enable me to basically insert a function 
call before and after each try: block at import time. Is that correct so 
far? That sounds not so bad at all.


However, if that only works due to importing it is not a solution. I 
need to make sure I catch all try: blocks, the current stack is in (and 
is about to step into).

Ah yes, and it should work with Python 3 as well.


Regards,
Sven

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Hooking Mechanism when Entering and Leaving a Try Block "Sven R. Kunze" <srkunze@mail.de> - 2015-08-12 20:44 +0200

csiph-web