diff options
| author | Jason Madden <jamadden@gmail.com> | 2020-02-06 10:48:04 -0600 |
|---|---|---|
| committer | Jason Madden <jamadden@gmail.com> | 2020-02-07 10:59:11 -0600 |
| commit | a825e5f29e98c8c84076600323ffe791531ac765 (patch) | |
| tree | fbc45814c37382cfa825e4a5f9161cab571f77e2 /src/zope/interface/interface.py | |
| parent | cc537c613ba6dd1a076202e2144fdacfccc520d2 (diff) | |
| download | zope-interface-a825e5f29e98c8c84076600323ffe791531ac765.tar.gz | |
Make verification errors more readable and useful.
Eliminate the trailing newlines and blank spaces (the code called them
"a stupid artifact").
Include the name of the defining interface (so the user can easily look up
any requirements on the attribute) and, for methods, the expected
signature (no more guessing about how many arguments are required!).
This is implemented by giving Attribute and Method useful reprs and strs.
Previously, they just had the defaults.
Fixes #170
Diffstat (limited to 'src/zope/interface/interface.py')
| -rw-r--r-- | src/zope/interface/interface.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/zope/interface/interface.py b/src/zope/interface/interface.py index b5d0e92..4ed447a 100644 --- a/src/zope/interface/interface.py +++ b/src/zope/interface/interface.py @@ -642,6 +642,22 @@ class Attribute(Element): interface = None + def _get_str_info(self): + """Return extra data to put at the end of __str__.""" + return "" + + def __str__(self): + of = self.interface.__name__ + '.' if self.interface else '' + return of + self.__name__ + self._get_str_info() + + def __repr__(self): + return "<%s.%s at 0x%x %s>" % ( + type(self).__module__, + type(self).__name__, + id(self), + self + ) + class Method(Attribute): """Method interfaces @@ -691,6 +707,8 @@ class Method(Attribute): return "(%s)" % ", ".join(sig) + _get_str_info = getSignatureString + def fromFunction(func, interface=None, imlevel=0, name=None): name = name or func.__name__ |
