Re: [Python-Dev] module customization

2017-11-16 Thread Brett Cannon
On Wed, 15 Nov 2017 at 16:27 Ethan Furman wrote: > So there are currently two ways to customize a module, with PEP 562 > proposing a third. > > The first method involves creating a standard class object, instantiating > it, and replacing the sys.modules entry with it. > > The second way is fairly

Re: [Python-Dev] module customization

2017-11-15 Thread Nathaniel Smith
On Wed, Nov 15, 2017 at 10:14 PM, Nathaniel Smith wrote: > On Wed, Nov 15, 2017 at 4:27 PM, Ethan Furman wrote: >> The second way is fairly similar, but instead of replacing the entire >> sys.modules entry, its class is updated to be the class just created -- >> something like sys.modules['mymod'

Re: [Python-Dev] module customization

2017-11-15 Thread Nathaniel Smith
On Wed, Nov 15, 2017 at 5:49 PM, Guido van Rossum wrote: >> If not, why not, and if so, shouldn't PEP 562's __getattr__ also take a >> 'self'? > > Not really, since there's only one module (the one containing the > __getattr__ function). Plus we already have a 1-argument module-level > __getattr__

Re: [Python-Dev] module customization

2017-11-15 Thread Nathaniel Smith
On Wed, Nov 15, 2017 at 4:27 PM, Ethan Furman wrote: > The second way is fairly similar, but instead of replacing the entire > sys.modules entry, its class is updated to be the class just created -- > something like sys.modules['mymod'].__class__ = MyNewClass . > > My request: Can someone write a

Re: [Python-Dev] module customization

2017-11-15 Thread Greg Ewing
Ethan Furman wrote: The second way is fairly similar, but instead of replacing the entire sys.modules entry, its class is updated to be the class just created -- something like sys.modules['mymod'].__class__ = MyNewClass . If the recent suggestion to replace the global namespace dict with the

Re: [Python-Dev] module customization

2017-11-15 Thread Guido van Rossum
On Wed, Nov 15, 2017 at 4:27 PM, Ethan Furman wrote: > So there are currently two ways to customize a module, with PEP 562 > proposing a third. > > The first method involves creating a standard class object, instantiating > it, and replacing the sys.modules entry with it. > > The second way is fa

[Python-Dev] module customization

2017-11-15 Thread Ethan Furman
So there are currently two ways to customize a module, with PEP 562 proposing a third. The first method involves creating a standard class object, instantiating it, and replacing the sys.modules entry with it. The second way is fairly similar, but instead of replacing the entire sys.modules en