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

Path csiph.com!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!border2.nntp.ams1.giganews.com!nntp.giganews.com!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <srkunze@mail.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'ast': 0.09; 'statements': 0.09; 'python': 0.10; 'stack': 0.13; 'importing': 0.15; 'thu,': 0.15; 'dislike': 0.16; 'pulls': 0.16; 'subject:when': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'try:': 0.18; 'solution.': 0.18; '2015': 0.20; 'aug': 0.20; 'context.': 0.22; 'am,': 0.23; 'insert': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'all.': 0.24; 'sort': 0.25; 'header:User-Agent:1': 0.26; 'chris': 0.26; 'correct': 0.28; 'function': 0.28; 'idea': 0.28; '13,': 0.29; 'code': 0.30; 'possibly': 0.32; 'rule': 0.33; 'received:10.0': 0.34; 'replace': 0.35; 'quite': 0.35; 'something': 0.35; 'step': 0.36; 'but': 0.36; 'should': 0.36; '(and': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'things': 0.38; 'sure': 0.39; 'well.': 0.40; 'to:addr:python.org': 0.40; 'received:de': 0.40; 'some': 0.40; 'skip:u 10': 0.61; 'no.': 0.62; 'charset:windows-1252': 0.62; 'due': 0.65; 'million': 0.74; 'sounds': 0.76
Date Wed, 12 Aug 2015 20:44:53 +0200
From "Sven R. Kunze" <srkunze@mail.de>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
MIME-Version 1.0
To python-list@python.org
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>
In-Reply-To <CAPTjJmoqg9sA-QB3RoRPQFx1osOYyBzff-UX8f2zrzxWpt7sYQ@mail.gmail.com>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-purgate clean
X-purgate This mail is considered clean (visit http://www.eleven.de for further information)
X-purgate-type clean
X-purgate-Ad Categorized by eleven eXpurgate (R) http://www.eleven.de
X-purgate This mail is considered clean (visit http://www.eleven.de for further information)
X-purgate clean
X-purgate-size 1087
X-purgate-ID 154282::1439405095-00000776-490FB1BD/0/0
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.132.1439405104.3627.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1439405104 news.xs4all.nl 2834 [2001:888:2000:d::a6]:38421
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 4275
X-Received-Body-CRC 1704933607
Xref csiph.com comp.lang.python:95306

Show key headers only | 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