Only catch AttributeError instead of everything.
Fixes#200
Note that this does break a doctest in five.intid (it's expecting a TypeError but it now gets Acquisition's RuntimeError).
Previously it manually walked up __bases__, meaning the answers could be inconsistent.
Fixes#190.
Also fixes several minor issues in the documentation, mostly cross-reference related.
Fixes#21
The 'mostly' is because interfaces are used in cases that C3 forbids;
when there's a conflict, we fallback to the legacy algorithm. It turns
out there are few conflicts (13K out of 149K total orderings in Plone).
I hoped the fix for #8 might shake out automatically, but it didn't.
Optimize the extremely common case of a __bases__ of length one.
In the benchmark, 4/5 of the interfaces and related objects have a base of length one.
Fix the bad IROs in the bundled ABC interfaces, and implement a way to get warnings or errors.
In running plone/buildout.coredev and tracking the RO requests, the
stats for equal, not equal, and inconsistent-so-fallback, I got
{'ros': 148868, 'eq': 138461, 'ne': 10407, 'inconsistent': 12934}
Add the interface module to the Attribute str.
This was extremely helpful tracking down the Plone problem; IDate is defined in multiple modules.
The query functions now start by looking at the next class in the MRO (interfaces directly provided by the underlying object are not found).
Adapter registries automatically pick up providedBy change to start finding the correct implementations of adapters, but to make that really useful they needed to change to unpack super() arguments and pass __self__ to the factory.
Fixes#11
Unfortunately, this makes PyPy unable to build the C extensions.
Additional crash-safety for adapter lookup.
Make the C functions get the cache only after resolving the
``required`` into a tuple, in case of side-effects like...clearing the
cache. This could lead to the ``cache`` object being deallocated
before we used it.
Drop the ``tuplefy`` function in favor of a direct call to
``PySequence_Tuple``. It's what the ``tuple`` constructor would do
anyway and saves a few steps.
Make sure that getting ``providedBy(super())`` and
``implementedBy(super())`` have no side effects.
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
Fixes#153
The items that went in each ``__all__`` are based on what is
documented:
$ rg --no-filename 'import' docs/ -trst | tr -s "[:blank:]" | sort | uniq | grep zope
>>> from pprint import pprint
>>> from zope.interface import *
>>> from zope.interface import Interface
>>> from zope.interface import Interface, Attribute, implementer
>>> from zope.interface import alsoProvides
>>> from zope.interface import classImplements
>>> from zope.interface import classImplementsOnly
>>> from zope.interface import directlyProvidedBy
>>> from zope.interface import directlyProvides
>>> from zope.interface import implementedBy
>>> from zope.interface import implementer
>>> from zope.interface import implementer_only
>>> from zope.interface import noLongerProvides
>>> from zope.interface import providedBy
>>> from zope.interface import provider
>>> from zope.interface.adapter import AdapterRegistry
>>> from zope.interface.declarations import Declaration
>>> from zope.interface.declarations import InstanceDeclarations
>>> from zope.interface.declarations import ProvidesClass
>>> from zope.interface.declarations import named
>>> from zope.interface.exceptions import BrokenImplementation
>>> from zope.interface.exceptions import Invalid
>>> from zope.interface.interface import Specification
>>> from zope.interface.interface import adapter_hooks
>>> from zope.interface.verify import verifyObject
>>> import gc
>>> import zope.interface
And also some personal judgement about what the public API is that I'm
more than happy to have reviewed.
Turns out they can be called in some very strange error cases. See #162 and #163 for details.
This should fix#162 (at least the provided test case, five.intid, passes now).
It also does enough work on #163 that (a) the test can be written and run in pure-python mode, which was needed to debug it and (b) five.intid runs in pure-python mode (well, with a bunch of other small hacks to Acquisition, ExtensionClass, DocumentTemplate and AccessControl), but I won't claim that it fully fixes#163. For one thing, there are no specific tests. For another, I see more such differences.
Instead of storing 1 and 2 attributes, respectively, in __dict__. This lets us eliminate inst_attr and its use of an undocumented API.
It also helps reign in the size of these objects. Before, on CPython 8, a ClassProvides object that subclasses both SpecificationBase and ClassProvidesBase required 408 bytes: 48 for the object, 360 for the dict.
Now it requires 72 + 232 = 304.
With a bit of work on defining __slots__ in Python, that can be brought much lower still, I think.
zope.security tests pass with this installed.
Turns out that the C extensions build and work fine with PyPy, but don't use them by default. Let them
be forced, though.
Tests needed some refactoring to account for the various permutations.
* Fixes#12 - registering instance methods as listeners doesn’t allow to easily unregister them as the registry tries to find the handler with 'is' but it should use '==' to allow the python BoundMethod wrapper (which is a new instance every time instance.$methodname is accessed).
This is an alternative to #86 and was suggested by @mgedmin in #85.
There are tests to be sure this works for subclasses like Pyramid's
Registry that extend dict too.
This doesn't change the pickle format, we were storing the output of
object.__reduce__ previously.
- The bare import of '_zope_c_optimizations' prevented them from being
used.
- After enabling them via absolute imports, they would fail due to
http://bugs.python.org/issue15657.
Fixes#60.
Fixes#46.
Benchmarks show a dramatic improvement; not quite as good as the
demonstration in #46 because the implementation had to be a bit more
complex to properly handle unregistration, but still very good. Here it
is with 20,000 items already registered:
```
%time add_to_reg(reg, 1000)
CPU times: user 190 ms, sys: 19.3 ms, total: 209 ms
Wall time: 203 ms
```
Here's a profile with about 100,000 utilities registered:
```
%prun add_to_reg(reg, 1000)
80005 function calls (79005 primitive calls) in 0.713 seconds
Ordered by: internal time
ncalls tottime percall cumtime percall filename:lineno(function)
1000 0.596 0.001 0.621 0.001 adapter.py:202(subscribe)
12000 0.016 0.000 0.019 0.000 interface.py:518(__hash__)
1000 0.010 0.000 0.709 0.001 registry.py:206(registerUtility)
3000/2000 0.009 0.000 0.014 0.000 interface.py:255(interfaces)
2000 0.008 0.000 0.022 0.000 adapter.py:637(changed)
1000 0.008 0.000 0.025 0.000 registry.py:498(_getUtilityProvided)
9000 0.008 0.000 0.017 0.000 {method 'get' of 'dict' objects}
1000 0.008 0.000 0.027 0.000 adapter.py:102(register)
2000 0.006 0.000 0.008 0.000 adapter.py:450(changed)
1000 0.005 0.000 0.663 0.001 registry.py:145(registerUtility)
```
I was very careful not to change the pickle at all.
zope.interface and zope.component tests have been run and both pass. (It
was necessary to account for the underlying objects changing because of
the way zope.component cleans up after tests.)