On 30 November 2017 at 22:38, Ilya Kulakov <kulakov.i...@gmail.com> wrote:
> A very rough implementation: > > typing.py: > > class _GenericMetaNoop(type): > def __getitem__(self, params): > return self > > class _GenericNoop(metaclass=_GenericMetaNoop) > pass > > GenericStub = Generic if TYPE_CHECKING else _GenericNoop > > elsewhere.py: > > import typing > > T = typing.TypeVar('T') > > class MyClass(typing.GenericStub[T]): > pass > > OK, I see. Note that all type checkers known to me never actually read content of typing.py (it is always heavily special cased). Therefore, one can safely write `GenericStub = _GenericNoop`. Anyway, my expectation is that going along this way (i.e. removing all runtime API apart from a necessary minimum) will give a minor speed-up as compared to PEP 560 at the cost of a breaking change (even for small number of developers). PEP 560 already gives overhead of 80% as compared to normal classes in worst case scenario (empty body with a single generic base). This is actually less than for ABCs (they can give up to 120% in worst case scenario). Moreover, performance is not a single motivation for PEP 560, there are other arguments such as metaclass conflicts which will not be solved without the machinery proposed by the PEP. -- Ivan
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/