zope.interface icon indicating copy to clipboard operation
zope.interface copied to clipboard

Why is verify*'s argument-name-code commented out?

Open Julian opened this issue 7 years ago • 6 comments

Hi!

I noticed that zope.interface.verify* are not verifying argument names.

It appears that https://github.com/zopefoundation/zope.interface/blob/master/src/zope/interface/verify.py#L108-L111 is commented out, but I can't find why in the history.

Is there a reason why that's been commented out (seemingly since 2007)?

(Sample code that unexpectedly passes:

from zope.interface import Interface, implementer, verify
class IFoo(Interface):
    def method(a, b):
        pass

@implementer(IFoo)
class Foo(object):
    def method(self, c, d):
        pass

verify.verifyObject(IFoo, Foo())

)

Julian avatar Nov 16 '16 19:11 Julian

(Sorry -- to elaborate, I know that signature comparison is somewhere between annoying, hard, and impossible :) -- so perhaps the real question is "would anyone like a patch to make such a thing enabled-by-default-but-toggleable-off", if the reasoning here was something to do with that fragility)

Julian avatar Nov 16 '16 19:11 Julian

@Julian It seems this code was already commented out when it was added to Zope3 more than 13 years ago, see

  • http://svn.zope.org/?limit_changes=0&view=rev&revision=8532 resp.
  • http://svn.zope.org/Zope3/trunk/src/zope/interface/verify.py?limit_changes=0&view=markup&pathrev=8532

There must have been a CVS repository of Interface before where the code was taken from but http://cvs.zope.org is no more.

icemac avatar Nov 18 '16 08:11 icemac

@Julian Memory eludes me, as well. Perhaps @jimfulton has a notion?

tseaver avatar Dec 06 '16 12:12 tseaver

I don't remember the occasion of commenting this out, but I don't think it's a good idea to verify positional argument names, because they are positional. :) I'm guessing that this was commented out because it caused breakage.

Python doesn't make a clean distinction between positional and named arguments (although Python 3 allows definition of arguments that must be provided by name). Often positional argument are obscured discourage their use by name, but this is informal.

jimfulton avatar Dec 07 '16 15:12 jimfulton

@jimfulton I agree that verifying positional arguments is not very useful. In any library I create (and in libraries I see from people who have enough detail generally to even care about these things), argument names I think do tend to be part of their stable public API -- i.e., one promises not to rename def func(foo, bar) to def func(foo2, bar).

But I personally don't ever guarantee not to reorder arguments (mostly because I discourage passing arguments positionally pretty much ever personally).

So for my own things I'd always want to verify the names of arguments in an interface, and never their position.

I can definitely understand wanting to not verify either thing though, especially since I certainly don't think this particular point is paid a ton of attention by library authors, but how do you feel about making it toggleable?

Julian avatar Dec 07 '16 16:12 Julian

Maybe have something like verify.verifyObject(IFoo, Foo(), positional=True) But it looks like this is now checked by mypy... so mabye this is now of a lower priority in zope.

adiroiban avatar Jul 09 '20 11:07 adiroiban