Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-20 Thread Brett Cannon
On Thu, 14 Sep 2017 at 12:09 Ivan Levkivskyi wrote: > On 14 September 2017 at 01:13, Guido van Rossum wrote: > >> >> That last sentence is a key observation. Do we even know whether there >> are (non-toy) things that you can do *in principle* with __class__ >> assignment but which are too slow *

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-14 Thread Ivan Levkivskyi
On 14 September 2017 at 23:02, Ivan Levkivskyi wrote: > On 14 September 2017 at 22:07, Ethan Furman wrote: > >> For comparison's sake, what would the above look like using __class__ >> assignment? And what is the performance difference? >> >> > FWIW I found a different solution: > > # file mod.

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-14 Thread Ivan Levkivskyi
On 14 September 2017 at 22:07, Ethan Furman wrote: > For comparison's sake, what would the above look like using __class__ > assignment? And what is the performance difference? > > FWIW I found a different solution: # file mod.py from typing_extensions import allow_forward_references allow_for

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-14 Thread Ivan Levkivskyi
On 14 September 2017 at 22:21, Ivan Levkivskyi wrote: > On 14 September 2017 at 22:07, Ethan Furman wrote: > >> >> For comparison's sake, what would the above look like using __class__ >> assignment? And what is the performance difference? >> >> > Actually I tried but I can't implement this wit

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-14 Thread Ivan Levkivskyi
On 14 September 2017 at 22:07, Ethan Furman wrote: > > For comparison's sake, what would the above look like using __class__ > assignment? And what is the performance difference? > > Actually I tried but I can't implement this without module __getattr__ so that one can just write: from typing_e

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-14 Thread Ethan Furman
On 09/14/2017 12:08 PM, Ivan Levkivskyi wrote: On 14 September 2017 at 01:13, Guido van Rossum wrote: That last sentence is a key observation. Do we even know whether there are (non-toy) things that you can do *in principle* with __class__ assignment but which are too slow *in practice* to b

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-14 Thread Ivan Levkivskyi
(sorry for obvious mistakes in the example in previous e-mail) On 14 September 2017 at 21:08, Ivan Levkivskyi wrote: > On 14 September 2017 at 01:13, Guido van Rossum wrote: > >> >> That last sentence is a key observation. Do we even know whether there >> are (non-toy) things that you can do *i

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-14 Thread Ivan Levkivskyi
On 14 September 2017 at 01:13, Guido van Rossum wrote: > > That last sentence is a key observation. Do we even know whether there are > (non-toy) things that you can do *in principle* with __class__ assignment > but which are too slow *in practice* to bother? And if yes, is __getattr__ > fast eno

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-13 Thread Guido van Rossum
On Wed, Sep 13, 2017 at 3:01 PM, Ivan Levkivskyi wrote: > @Guido > > One would have to introduce some kind of convention > > where you can write properties with a leading _ > > One doesn't even need the @property decorator in this case. > For example: > > def __getattr__(name): > g = globals(

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-13 Thread Ivan Levkivskyi
@Guido > One would have to introduce some kind of convention > where you can write properties with a leading _ One doesn't even need the @property decorator in this case. For example: def __getattr__(name): g = globals() name = '_' + name if name in g: return g[name]() rai

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-13 Thread Guido van Rossum
On Wed, Sep 13, 2017 at 2:00 PM, Nathaniel Smith wrote: > On Wed, Sep 13, 2017 at 11:49 AM, Guido van Rossum > wrote: > > > Why not adding both? Properties do have their uses as does > __getattr__. > > > > In that case I would just add __getattr__ to module.c, and add a recipe > or > > perhaps

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-13 Thread Nathaniel Smith
On Wed, Sep 13, 2017 at 11:49 AM, Guido van Rossum wrote: > > Why not adding both? Properties do have their uses as does __getattr__. > > In that case I would just add __getattr__ to module.c, and add a recipe or > perhaps a utility module that implements a __getattr__ you can put into your > mod

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-13 Thread Guido van Rossum
> Why not adding both? Properties do have their uses as does __getattr__. In that case I would just add __getattr__ to module.c, and add a recipe or perhaps a utility module that implements a __getattr__ you can put into your module if you want @property support. That way you can have both but yo

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-13 Thread Sven R. Kunze
Why not adding both? Properties do have their uses as does __getattr__. Cheers, Sven On 13.09.2017 11:43, Larry Hastings wrote: On 09/12/2017 12:38 AM, Larry Hastings wrote: On 09/11/2017 07:22 PM, Guido van Rossum wrote: The prototype is linked to from the PEP; for your convenience

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-13 Thread Larry Hastings
On 09/12/2017 12:38 AM, Larry Hastings wrote: On 09/11/2017 07:22 PM, Guido van Rossum wrote: The prototype is linked to from the PEP; for your convenience here's a link: https://github.com/larryhastings/cpython/tree/module-properties

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-12 Thread Ivan Levkivskyi
@Larry > "@property" 375 hits > "def __getattr__" 28 hits I don't think it is fair to compare occurrences of __getattr__ vs occurrences of @property, since in the first case one would use a single __getattr__ per class, while in the second case @property is required for every attribute. @G

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-12 Thread Larry Hastings
On 09/11/2017 07:22 PM, Guido van Rossum wrote: I still don't follow. How does one use InstanceDescriptor? If you write a class that inherits from InstanceDescriptor and supports the descriptor protocol, module objects will call the descriptor protocol functions when that object is accessed

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-11 Thread Guido van Rossum
On Mon, Sep 11, 2017 at 6:04 PM, Larry Hastings wrote: > > > On 09/11/2017 08:44 AM, Guido van Rossum wrote: > > I worry that in the end @property isn't general enough and the major use > cases end up still having to use __class__ assignment, and then we'd have a > fairly useless feature that we

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-11 Thread Ethan Furman
On 09/06/2017 08:26 AM, Guido van Rossum wrote: So we've seen a real use case for __class__ assignment: deprecating things on access. That use case could also be solved if modules natively supported defining __getattr__ (with the same "only used if attribute not found otherwise" semantics as i

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-11 Thread Larry Hastings
On 09/11/2017 08:44 AM, Guido van Rossum wrote: I worry that in the end @property isn't general enough and the major use cases end up still having to use __class__ assignment, and then we'd have a fairly useless feature that we cant withdraw, ever. What can I say--I don't have that worry ;-)

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-11 Thread Chris Barker
On Mon, Sep 11, 2017 at 10:20 AM, Victor Stinner wrote: > 2017-09-11 19:00 GMT+02:00 Chris Barker : > > There are a heck of a lot in the os module: > > ['get_blocking', > > This one is not a good example: it takes a parameter. You cannot > convert it to a property. > I'm sure there are many that

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-11 Thread Victor Stinner
2017-09-11 19:00 GMT+02:00 Chris Barker : > I wish there were a property feature available almost very time I encounter > a "get*" method in the stdlib (or any where): > > There are a heck of a lot in the os module: > > In [4]: [s for s in dir(os) if s.startswith('get')] > Out[4]: > > ['get_blockin

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-11 Thread Chris Barker
On Thu, Sep 7, 2017 at 3:49 PM, Larry Hastings wrote: > But I can cite at least one place in the standard library that would have > been better if it'd been implemented as a module property: > os.stat_float_times(). > I wish there were a property feature available almost very time I encounter a

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-11 Thread Guido van Rossum
On Sun, Sep 10, 2017 at 8:52 PM, Larry Hastings wrote: > > On 09/06/2017 02:13 PM, Ronald Oussoren wrote: > > To be honest this sounds like a fairly crude hack. Updating the __class__ > of a module object feels dirty, but at least you get normal behavior w.r.t. > properties. > > Okay. Obviously I

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-10 Thread Larry Hastings
On 09/06/2017 02:13 PM, Ronald Oussoren wrote: To be honest this sounds like a fairly crude hack. Updating the __class__ of a module object feels dirty, but at least you get normal behavior w.r.t. properties. Okay. Obviously I disagree, I think it's reasonable. But I'll assume you're -1.

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-10 Thread Larry Hastings
On 09/06/2017 08:26 AM, Guido van Rossum wrote: So we've seen a real use case for __class__ assignment: deprecating things on access. That use case could also be solved if modules natively supported defining __getattr__ (with the same "only used if attribute not found otherwise" semantics as

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-07 Thread Larry Hastings
On 09/07/2017 03:49 PM, Larry Hastings wrote: Excluding Lib/test, there are 375 uses of "@property" in the stdlib in trunk, 60 uses of __getattr__, and 34 of __getattribute__. I spent a minute looking at the output and realized there were a bunch of hits inside pydoc_data/topics.py, aka docu

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-07 Thread Larry Hastings
On 09/06/2017 09:45 AM, Guido van Rossum wrote: So we're looking for a competing PEP here. Shouldn't be long, just summarize the discussion about use cases and generality here. I don't think it's necessarily a /competing/ PEP; in my opinion, they serve slightly different use cases. After al

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-07 Thread Neil Schemenauer
Larry Hastings wrote: > The TL;DR summary: add support for property objects to modules. > I've already posted a prototype. I posted an idea to python-ideas about lazy module loading. If the lazy loading idea works, having properties would allow modules to continue to be "lazy safe" but to easily

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-06 Thread Ronald Oussoren
> On 6 Sep 2017, at 00:03, Larry Hastings wrote: > > > > I've written a PEP proposing a language change: > https://www.python.org/dev/peps/pep-0549/ > > The TL;DR summary: add support for property objects to modules. I've already > posted a protot

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-06 Thread Koos Zevenhoven
On Wed, Sep 6, 2017 at 1:52 AM, Nathaniel Smith wrote: ​[...]​ > import sys, types > class _MyModuleType(types.ModuleType): > @property > def ... > > @property > def ... > sys.modules[__name__].__class__ = _MyModuleType > > It's definitely true though that they're not the most ob

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-06 Thread Cody Piersall
On Wed, Sep 6, 2017 at 10:26 AM, Guido van Rossum wrote: > > So we've seen a real use case for __class__ assignment: deprecating things on > access. That use case could also be solved if modules natively supported > defining __getattr__ (with the same "only used if attribute not found > otherwi

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-06 Thread Guido van Rossum
On Wed, Sep 6, 2017 at 9:15 AM, Ivan Levkivskyi wrote: > > On 6 September 2017 at 17:26, Guido van Rossum wrote: > >> >> Is there a real use case for @property? Otherwise, if we're going to mess >> with module's getattro, it makes more sense to add __getattr__, which would >> have made Nathaniel

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-06 Thread Ivan Levkivskyi
On 6 September 2017 at 17:26, Guido van Rossum wrote: > > Is there a real use case for @property? Otherwise, if we're going to mess > with module's getattro, it makes more sense to add __getattr__, which would > have made Nathaniel's use case somewhat simpler. (Except for the __dir__ > thing -- w

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-06 Thread Guido van Rossum
So we've seen a real use case for __class__ assignment: deprecating things on access. That use case could also be solved if modules natively supported defining __getattr__ (with the same "only used if attribute not found otherwise" semantics as it has on classes), but it couldn't be solved using @p

Re: [Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-05 Thread Nathaniel Smith
On Tue, Sep 5, 2017 at 3:03 PM, Larry Hastings wrote: > > I've written a PEP proposing a language change: > > https://www.python.org/dev/peps/pep-0549/ > > The TL;DR summary: add support for property objects to modules. I've > already posted a prototype. Interesting idea! It's definitely less ar

[Python-Dev] PEP 549: Instance Properties (aka: module properties)

2017-09-05 Thread Larry Hastings
I've written a PEP proposing a language change: https://www.python.org/dev/peps/pep-0549/ The TL;DR summary: add support for property objects to modules. I've already posted a prototype. How's that sound? //arry/ ___ Python-Dev mailing list