[Python-ideas] __intancehook__ special method

Yahya Abou 'Imran yahya-abou-imran at protonmail.com
Tue Dec 26 07:02:49 EST 2017


Well, I fact, I was playing with metaclasses and descriptors, and I was thinking about a way to use the famous variable annotation to instatiate decrptors like this:

class Point(metaclass=MyMeta):
    x: int
    y: int

class Circle(metaclass=MyMeta):
    center: Point
    radius: PositiveInteger

Here the radius must be [strictly] positive, but since I'm using the annotations to get the type to test in the __set__ method of the descriptor, I didn't found a more elegant way than that...

And it was before I knew the existance of dataclasses!!! I was pretty shocked by the way. Maybe I can make this compatible with it anyway.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20171226/7ad8bb95/attachment.html>


More information about the Python-ideas mailing list