On 14 September 2017 at 01:13, Guido van Rossum <guido@python.org> 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 combinationof three factors:* modest performance improvement* some people might find __getattr__ clearer than __class__ assignment* this would be consistent with how stubs workIMO we're still looking for applications._______________________________________________How about thisdef allow_forward_references(*allowed):caller_globals = sys._getframe().__globals__def typing_getattr(name):if name in allowed:return nameraise AttributeError(...)caller_globals.__getattr__ = typing_getattrfrom typing_extensions import allow_forward_referencesallow_forward_references('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! :-)--Ivan
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/brett%40python.org