connor-makowski / type_enforced

A pure python type enforcer for annotations. Enforce types in python functions and methods.
MIT License
45 stars 2 forks source link

Support zope Interfaces #42

Open perkinslr opened 2 weeks ago

perkinslr commented 2 weeks ago

Zope Interfaces are still often used in software using twisted and related technologies. It would be nice if type_enforced supported these interfaces in its type checking.

The critical checker is provided by zope.interface.verify.verifyObject(iface, candidate, tentative), where tentative indicates if objects that just happen to provide the interface are good enough, or if they must explicitly support it.

Note this can sorta be done via GenericConstraints, but those run after the rest of the type checking, so you have to pick between a constraint for an interface, or a basic type. So you cannot do def foo(bar: [int, IBar]):

connor-makowski commented 1 day ago

From my perspective, this poses some challenges. 1) It is important for us to keep type_enforced pure python and without any deps. 2) The zope interface is fairly non pythonic. If we add support for this, are there other packages we would want to support?

How do you envision support for Zope would look?