Commit Graph

167 Commits

Author SHA1 Message Date
Jason Madden 84872a8d2a
Remove the bare except: statements.
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).
2020-04-02 07:53:05 -05:00
Jason Madden abf12ada0a
Back to development: 5.0.3 2020-03-30 09:43:48 -05:00
Jason Madden 59715c4508
Preparing release 5.0.2 2020-03-30 09:42:51 -05:00
Jason Madden bfedd6f587
Ensure that objects that implement no interfaces still have Interface in their iro and sro.
Fixes #197.
2020-03-30 08:55:56 -05:00
Jason Madden 1b83ad47e4
Back to development: 5.0.2 2020-03-21 08:24:27 -05:00
Jason Madden 023f1d5c83
Preparing release 5.0.1 2020-03-21 08:24:00 -05:00
Jason Madden a11e1ea7ce
Make the RO for InterfaceClass consistent and fix handling of the STRICT_IRO env variable.
Fixes #192 and fixes #194.

Also fix the IRO for OrderedDict on CPython 2
2020-03-20 10:16:44 -05:00
Jason Madden 3a50f2e887
Back to development: 5.0.1 2020-03-19 07:45:53 -05:00
Jason Madden 953ba424a6
Preparing release 5.0.0 2020-03-19 07:45:28 -05:00
Jason Madden 6be183e34d
Add additional tests for assigning to Interface.__module__. 2020-03-18 12:29:51 -05:00
Jason Madden a2687a6425
Add tests for comparing InterfaceClass/Implements objects to things without the required attributes.
And fix the C handling of this case.
2020-03-18 12:28:13 -05:00
Jason Madden 4c4e1c985f
Ensure Interface is the last item in the __sro__.
None of the elegant solutions mentioned in the issue worked out, so I had to brute force it.

Fixes #8
2020-03-18 12:06:17 -05:00
Jason Madden e1e94a0da9
More minor documentation fixups.
Mostly formatting. Some interfaces were being documented as clasess, which doesn't work.
2020-03-18 09:55:33 -05:00
Jason Madden f4b777d4a5
Make Interface.getTaggedValue follow the __iro__.
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.
2020-03-18 07:44:12 -05:00
Jason Madden 024f643227
Use C3 (mostly) to compute IRO.
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.
2020-03-15 09:56:14 -05:00
Jason Madden 354faccebd
Merge pull request #181 from zopefoundation/issue11
Make provided/implementedBy and adapter registries respect super().
2020-03-10 06:16:45 -05:00
Marius Gedminas e5221d3afe Update changelog 2020-03-10 09:54:22 +02:00
Jason Madden 1e720c3819
Make provided/implementedBy and adapter registries respect super().
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.
2020-03-09 12:51:18 -05:00
Jason Madden d088fd500d
Update documentation and clarify the relationship of the older mapping and sequence interfaces. 2020-02-17 07:02:57 -06:00
Jens W. Klein 823faaaea1 Fix repr of "Attribute" to look like before
and as usual in Python.
2020-02-16 15:49:31 +01:00
Jason Madden f6d2e9445d
Make verifyObject/Class collect and raise all errors instead of only the first.
Fixes #171.
2020-02-08 07:57:35 -06:00
Jason Madden 83f4f55699
Add warning to change note about string changes breaking doctests.
Also tweak documentation to DRY for verifyObject/verifyClass.
2020-02-08 06:21:17 -06:00
Jason Madden a825e5f29e
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
2020-02-07 10:59:11 -06:00
Jason Madden 0b0e22727b
Fix verification for methods of builtin types with pseudo-default arguments on Pypy
On PyPy2, they are ignored (like on CPython), but on PyPy3 they can
actually be validated.

Fixes #118
2020-02-06 09:02:56 -06:00
Jason Madden 865c569bbe
Correct extra underscore. 2020-02-06 05:37:16 -06:00
Jason Madden c4805da768
Add __all__ to all modules.
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.
2020-02-05 08:12:53 -06:00
Jens W. Klein 8ab0194306 iPerformace optimization in _lookup _lookupAll _subscriptions 2020-02-04 19:55:23 +01:00
Jason Madden 97997956d1
The _empty singleton has no-op subscribe/unsubscribe methods.
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.
2020-01-28 16:04:31 -06:00
Jens W. Klein 24a8b54a8b Remove unneeded overwrite and call to anyway inherited __hash__ method 2020-01-28 10:53:20 +01:00
Jason Madden 61c6d54eba
Make the singleton _empty immutable.
Fixes #158
2020-01-27 15:54:53 -06:00
Jason Madden f41ebfdb0b
Remove support for hashing uninitialized interfaces.
Fixes #157
2020-01-27 09:31:30 -06:00
Jason Madden 7a34a32a3b
Avoid allocating space for tagged values unless they're used. This saves another few percent. 2020-01-27 07:43:27 -06:00
Jens W. Klein fbadf4a8ab Improve InterfaceClass __hash__ performance 2020-01-24 17:26:45 +01:00
Jason Madden 02e11f214c
Add PR links to CHANGES.rst for #151 and #154. [skip ci] 2020-01-23 07:07:47 -06:00
Jason Madden ddf670afb7
Use tp_members in SpecificationBase and ClassProvidesBase.
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.
2020-01-23 06:39:48 -06:00
Jason Madden b928f8a53c
Bump version as suggested in review.
Also add a line of missing whitespace.
2020-01-22 06:19:57 -06:00
Jason Madden e76d03f519
Test PURE_PYTHON at runtime.
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.
2020-01-21 09:38:45 -06:00
Marius Gedminas ef2617ee98 Fix GH issue URL 2019-11-21 10:46:45 +02:00
Marius Gedminas a7614c0e35 Back to development: 4.7.2 2019-11-11 18:57:04 +02:00
Marius Gedminas 180b34ed7e Preparing release 4.7.1 2019-11-11 18:56:53 +02:00
Marius Gedminas 50704399b1 Back to development: 4.7.1 2019-11-11 15:41:43 +02:00
Marius Gedminas 07f2d0c0a4 Preparing release 4.7.0 2019-11-11 15:41:30 +02:00
Colin Watson f9a6756929 Add a bit more spacing to CHANGES.rst 2019-11-11 11:45:25 +00:00
Colin Watson 58d17004cd Add support for Python 3.8 2019-11-11 10:54:03 +00:00
mauro 886fc5e236 changelog 2019-10-10 12:22:04 +02:00
Marius Gedminas e4b580e79b Drop support for Python 3.4 2019-08-17 14:59:57 +03:00
Jason Madden 06c901f605
Back to development: 4.6.1 2018-10-23 15:18:15 -05:00
Jason Madden 29d9fefba1
Preparing release 4.6.0 2018-10-23 15:17:39 -05:00
Jason Madden 7b67a79a8c
Fix 'verifyObject' for class objects with staticmethods on Python 3.
Fixes #126
2018-10-23 08:42:47 -05:00
Forest Gregg 4d7e58c485 add py3.7 to setup.py classifier, tox.ini, and CHANGES 2018-08-09 16:20:50 -05:00
Michael Howitz c1b436de3f Back to development: 4.5.1
[skip ci]
2018-04-19 08:27:50 +02:00
Michael Howitz f0a6a10a94 Preparing release 4.5.0
[skip ci]
2018-04-19 08:24:35 +02:00
Michael Howitz aed246cd0d Add change log entry for #115 fixing #114. 2018-04-19 08:23:32 +02:00
Joni Orponen bad4827689 Bump to 4.5.0. 2017-12-14 16:40:49 +01:00
‮rekcäH nitraM‮ d50e3d4bed Allow Registering and unregistering instance methods as listeners (#102)
* 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).
2017-11-28 08:28:40 +01:00
Marius Gedminas 3ce6b0c929 Back to development: 4.4.4 2017-09-22 10:46:26 +03:00
Marius Gedminas 8d2d94ddc6 Preparing release 4.4.3 2017-09-22 10:45:07 +03:00
Jason Madden 32e26fc242
Add change note. Fixes #100 2017-09-21 05:54:37 -05:00
Maxim Avanov 5162674b83 Drop __annotations__ in interface declarations 2017-09-01 16:29:44 +01:00
Jason Madden a34e5cbaa8
Back to development: 4.4.3 2017-06-14 17:30:04 -05:00
Jason Madden db06631f38
Preparing release 4.4.2 2017-06-14 17:29:25 -05:00
Jason Madden 751a950885
Fix the cache getting out of sync with _utility_registrations.
Fixes #93
2017-06-14 08:51:43 -05:00
Jason Madden 9de7239b28
Fix #85 by implementing __reduce__ to omit _v_ attributes.
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.
2017-06-14 06:51:22 -05:00
Jim Fulton 47cf89eee7 Back to development: 4.4.2 2017-05-13 09:28:54 -04:00
Jim Fulton 1fa2e84aba Preparing release 4.4.1 2017-05-13 09:28:35 -04:00
Jim Fulton c95f1e2e73 typo 2017-05-12 17:50:52 -04:00
Jim Fulton 38d1c82de8 Simply the caching of utility-registration data. In addition to
simplification, avoids spurious test failures when checking for
leaks in tests with persistent registries.
2017-05-12 17:20:59 -04:00
Tres Seaver 81f50ca160 Raise ValueError if non-text name passed to adapter registry methods.
Prevents corruption of lookup cache.

Alternative to fix proposed in #75.
2017-05-04 05:50:35 -04:00
Tres Seaver 33c4d9ce39 svb 2017-04-21 17:03:53 -04:00
Tres Seaver e57f5ddfaa Prep 4.4.0 release. 2017-04-21 17:03:14 -04:00
Tres Seaver f1b3346f2e Bump minor version due to new Python version support. 2017-04-21 17:00:57 -04:00
Jason Madden b8a36f1b6a Add support for Python 3.6. (#74)
* Add support for Python 3.6.

Also use macpython for all the mac builds. See
zopefoundation/persistent#59

* Install the test extra with pip.

hopefully this avoids the SSL issue seen in macpython
3.6 (https://travis-ci.org/zopefoundation/zope.interface/jobs/192367647)

Also update appveyor.yml
2017-01-18 10:33:35 -06:00
Jason Madden 5c08781ce9
Don't redefine METH_KEYWORDS
Instead, use the intended METH_KEYWORDS | METH_VARARGS spelling.

Fixes #71
2017-01-05 07:06:42 -06:00
Tres Seaver 947bd6da06 svb 2016-12-13 18:04:23 -05:00
Tres Seaver 3217ecd3e7 Prep 4.3.3 release. 2016-12-13 18:03:17 -05:00
Tres Seaver 03d1303915 Garden changelog.
[ci skip]
2016-12-13 18:00:43 -05:00
Jean Jordaan 188d97b39d Merge branch 'master' of github.com:zopefoundation/zope.interface
Conflicts:
	CHANGES.rst

I think that was the simplest conflict resolution ever :-]
2016-12-06 10:24:23 +07:00
Tres Seaver 53246e5362 Fix C optimizations broken on Py3k.
- 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.
2016-11-15 14:04:50 -05:00
Jean Jordaan f4a1c48698 Make changelog note more informative 2016-10-16 13:32:47 -04:00
Jean Jordaan 4631968f79 Changelog note 2016-10-16 12:51:33 -04:00
Marius Gedminas bcc55d4038 Back to development: 4.3.3 2016-09-05 09:11:20 +03:00
Marius Gedminas f407ba133f Preparing release 4.3.2 2016-09-05 09:11:02 +03:00
Jason Madden c0e980b4b9
Fix equality testing of implementedBy objects that have been proxied. Fixes #55. 2016-09-02 18:20:25 -05:00
Michael Howitz 69cacf26ff Back to development: 4.4.0 2016-08-31 14:45:05 +02:00
Michael Howitz f644e237c8 Preparing release 4.3.1 2016-08-31 14:44:31 +02:00
Jason Madden 14c8b29660 Support Components subclasses that are not hashable. (#54)
* Support Components subclasses that are not hashable.

Fixes #53.
2016-08-31 14:41:51 +02:00
Michael Howitz dae04c304b Back to development: 4.4.0 2016-08-31 09:19:40 +02:00
Michael Howitz aaeb59c64e Preparing release 4.3.0 2016-08-31 09:18:48 +02:00
Jason Madden 58ef487292
Use dictionary lookups for testing subscribed status.
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.)
2016-08-19 08:18:39 -05:00
Jason Madden 2081db253c
Make setuptools a hard dep of setup.py
Fixes #13
Fixes #14
2016-08-04 06:54:31 -05:00
Jason Madden bbf1a3d479
Make declarations.Implements sortable.
Fixes #42
2016-08-03 10:34:31 -05:00
Tres Seaver d88751d4cf svb 2016-06-10 10:00:49 -04:00
Tres Seaver 13eb0ed599 Prep 4.2.0 release. 2016-06-10 09:58:29 -04:00
Tres Seaver 0a0dad5c0b Drop support for Python 3.2. 2016-03-23 17:33:22 -04:00
Tres Seaver 582cc3d340 Drop support for Python 2.6.
Note explicit support for Python 3.5.

Bump next release for semver.
2016-03-09 13:20:07 -05:00
Marius Gedminas baa6844f11 Back to development: 4.1.4 2015-10-05 10:35:42 +03:00
Marius Gedminas d99c28ae9f Preparing release 4.1.3 2015-10-05 10:34:51 +03:00
Marius Gedminas 49348bf625 Update changelog 2015-10-05 10:32:30 +03:00
Tres Seaver 937b7a1125 svb 2014-12-27 19:47:53 -05:00
Tres Seaver 05a1200e58 Prep 4.1.2 release. 2014-12-27 19:46:25 -05:00