[Python-ideas] New Python syntax for continuing definitions for existing classes

Chris Angelico rosuav at gmail.com
Tue Sep 13 21:23:13 EDT 2016


On Wed, Sep 14, 2016 at 9:35 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Chris Angelico wrote:
>
>> It's a little bit magical, in that it looks up the original class
>> using globals();
>
>
> The way you've written it, monkeypatch() will only work
> if you call it from the module it's defined in.

Yes. You could tweak that by looking at cls.__module__ and grab it
from sys.modules, but I kept the example simple. However, I would NOT
use the standard name lookup mechanism.

ChrisA


More information about the Python-ideas mailing list