Path: csiph.com!weretis.net!feeder4.news.weretis.net!ecngs!testfeeder.ecngs.de!newsfeed.freenet.ag!newsfeed0.kamp.net!newsfeed.kamp.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Antoon Pardon Newsgroups: comp.lang.python Subject: Re: Case Statements Date: Thu, 17 Mar 2016 10:23:23 +0100 Lines: 39 Message-ID: References: <30502a2e-0bad-4b0f-a1e8-a2b40b0d7ab9@googlegroups.com> <56E928D4.3000701@rece.vub.ac.be> <56E93ADD.9040500@rece.vub.ac.be> <56E961C9.7040008@rece.vub.ac.be> <56E97B60.3060402@rece.vub.ac.be> <56E9A66E.4030905@rece.vub.ac.be> <56e9f7f9$0$1597$c3e8da3$5496439d@news.astraweb.com> <56ea0e4f$0$1585$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de 6NCZrggUDWqH99iuZ8uJ8waNzrnCQY7DHGhJ+1wP2BCw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:134': 0.05; 'main()': 0.07; 'python': 0.10; 'syntax': 0.13; 'def': 0.13; 'interpreter': 0.15; 'skip:p 40': 0.15; 'thu,': 0.15; '2")': 0.16; '2016': 0.16; 'attr': 0.16; 'foo()': 0.16; 'main():': 0.16; 'received:ac.be': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; "wouldn't": 0.16; 'language': 0.19; 'decorator': 0.22; 'either.': 0.22; 'tried': 0.24; 'header:In- Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'chris': 0.26; "i'm": 0.30; 'work.': 0.30; 'received:be': 0.30; 'skip:s 30': 0.31; 'class': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'though.': 0.33; 'depends': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'mean': 0.38; 'sure': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'skip:n 10': 0.62; 'mar': 0.65; 'angelico:': 0.84; 'guarantee.': 0.84; 'schreef': 0.84; 'thing,': 0.93 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AucKAIJ26laGuA9G/2dsb2JhbABehGEBJbwGhg0CggEBAQEBAQFlhGkBAQQjZgsYAgIFIQICDwJGEwYCAogjsQyLT4N5AQEIAh58hSKERIUIgjSBOgWXUoFQjDGJI4VijwJig2ZpimMBAQE User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.5.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:105079 Op 17-03-16 om 03:02 schreef Chris Angelico: > On Thu, Mar 17, 2016 at 12:54 PM, Steven D'Aprano wrote: > >> I wouldn't want to rely on it working with decorator syntax either. Even if >> it does now, I'm not sure that's a language guarantee. > That's the thing, though. It's not a guarantee, yet it does work in > every Python interpreter that I tried it in. That depends on what you mean by work. This failes: def monkeypatch(cls): orig = globals()[cls.__name__] print("Monkeypatch",id(cls),"into",id(orig)) for attr in dir(cls): if not attr.startswith("_"): setattr(orig,attr,getattr(cls,attr)) return orig def main(): class Foo: def method1(self): print("I am method 1") print("Foo is currently",id(Foo)) some_object = Foo() @monkeypatch class Foo: def method2(self): print("I am method 2") print("Foo is now",id(Foo)) some_object.method1() some_object.method2() main()