-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support zope Interfaces #42
Comments
From my perspective, this poses some challenges.
How do you envision support for Zope would look? |
With a soft runtime dependency, you can easily check if an argument provides an interface. Initially I thought to include an optional kw argument to Enforcer to tell it to perform interface checking, as the function mentioned above is the only simple way to handle incidental implementations. However, I understand the desire to avoid adding even a soft dependency, so I found an introspective solution that better fits with
This could be gated behind a kw argument to Enforcer, to avoid extraneous Anyway, that's the "how", the "do we want to" is another matter. I don't know of any other packages that are along similar lines, certainly none that are as wide spread and long standing as zope. (zope is used by twisted, so is indirectly used in lots of enterprise environments). It is probably worth noting that there is an actively maintained mypy plugin for zope to support lint-time type checking. As for being non-pythonic, the same was said about deferreds and asynchronous programming before asyncio made them popular. Same with the very ability to specify type annotations. That said, I know what it's like to have drive-by suggestions to increase project scope and complexity, so if you think this is outside your project's scope, I won't argue against that. |
I started looking into this I ran into a key issue: Something unexpected is occurring when I try to see if from zope.interface import Interface, implementer
from pprint import pp as print
class IGreeter(Interface):
def greet(name: str) -> str:
"""Greets the person with the given name."""
@implementer(IGreeter)
class Greeter:
def greet(self, name: str) -> str:
return f"Hello, {name}!"
print({
'hasattr': hasattr(IGreeter, '__provides__'),
'in_dir': "__provides__" in dir(IGreeter),
'isinstance': isinstance(IGreeter, Interface),
'issubclass': issubclass(IGreeter, Interface),
'dir': dir(IGreeter),
}) Gives:
It seems like the sope interface overrides the dir method but is not actually implementing an attr. Can you look into that and see if you cant figure out a way to list the IGreeter acceptable classes? |
I take it you are trying to expand the list of
|
This is starting to seem like it will not be particularly general. I am now thinking this might be good motivation to allow extending the base type enfoced class for more complex cases like this. Something that is not a constraint. Let me mull this over a bit. |
Zope Interfaces are still often used in software using
twisted
and related technologies. It would be nice iftype_enforced
supported these interfaces in its type checking.The critical checker is provided by
zope.interface.verify.verifyObject(iface, candidate, tentative)
, wheretentative
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]):
The text was updated successfully, but these errors were encountered: