Worth maybe noting that this could play interestingly with PEP 484?
-- Ryan (ライアン) Yoko Shimomura, ryo (supercell/EGOIST), Hiroyuki Sawano >> everyone else https://refi64.com/ On May 4, 2019, 8:24 PM -0500, Serge Matveenko <s...@matveenko.ru>, wrote: > Hi, all! > > I believe, almost everybody is familiar with the `abc` package. > > The problem is that the ABC class is not a separate thing from > `object`. So, using ABCs often results in complicated inheritance > designs and even in the infamous metaclass conflict. > > Another problem is that ABC performs checks at the moment an object is > being instantiated which isn't exactly the way one expects an > interface to work. The obvious way would be to enforce the > implementation at the moment `type` for that class is created, i.e. on > module execution time. > > I'm aware there was `PEP 245 -- Python Interface Syntax` which was > rejected. However, I agree with the idea that the syntax proposed in > this PEP wasn't particularly "pythonish". > > So, I would like to propose adding a third main object called > `interface` in addition to `object` and `type` and to use it to define > interface objects. Such interfaces could then be used in the class > definition in the following way. > > ``` > class MyInterfaceA(interface): > def foo(): > pass > > class MyInterfaceB(interface): > def bar(): > pass > > class Implementation(implements=[MyInterfaceA, MyInterfaceB]): > def foo(): > pass > def bar(): > pass > ``` > > As a proof of concept, I've implemented a library which implements the > idea and allows to use this approach right out of the box — > https://pypi.org/project/strict-interfaces/. > > I would like to get any feedback for the idea and the library. > > Thanks to all! > _______________________________________________ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/