[Python-Dev] PEP 549: Instance Properties (aka: module properties) (original) (raw)
Ethan Furman ethan at stoneleaf.us
Thu Sep 14 16:07:55 EDT 2017
- Previous message (by thread): [Python-Dev] PEP 549: Instance Properties (aka: module properties)
- Next message (by thread): [Python-Dev] PEP 549: Instance Properties (aka: module properties)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 bother? And if yes, is getattr fast enough? @property? I myself have never implemented deprecation warnings management nor lazy loading, so it is hard to say if class assignment is fast enough. For me it is more combination of three factors: * modest performance improvement * some people might find getattr clearer than class assignment * this would be consistent with how stubs work IMO we're still looking for applications.
How about this def allowforwardreferences(*allowed): callerglobals = sys.getframe().globals def typinggetattr(name): if name in allowed: return name raise AttributeError(...) callerglobals.getattr = typinggetattr from typingextensions import allowforwardreferences allowforwardreferences('Vertex', 'Edge') T = TypeVar('T', bound=Edge) class Vertex(List[Edge]): def copy(self: T) -> T: ... class Edge: ends: Tuple[Vertex, Vertex] ... Look mum, no quotes! :-)
For comparison's sake, what would the above look like using class assignment? And what is the performance difference?
--
Ethan
- Previous message (by thread): [Python-Dev] PEP 549: Instance Properties (aka: module properties)
- Next message (by thread): [Python-Dev] PEP 549: Instance Properties (aka: module properties)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]