summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* Update comments and add a test for more coverage.Jason Madden2020-03-193-52/+104
|
* Remove untested except in the metaclass __new__.faster-eq-hash-comparisonJason Madden2020-03-181-7/+5
| | | | Reviewers weren't sure how it could be raised.
* Add additional tests for assigning to Interface.__module__.Jason Madden2020-03-181-0/+7
|
* Add tests for comparing InterfaceClass/Implements objects to things without ↵Jason Madden2020-03-184-14/+142
| | | | | | the required attributes. And fix the C handling of this case.
* Several small tweaks to GC and deletion handling.Jason Madden2020-03-181-5/+11
| | | | Several places needed to, essentially, call super.
* Move to a metaclass for handling __module__.Jason Madden2020-03-181-62/+108
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This offers the absolute best performance at what seems like reasonable complexity. +-------------------------------------------------------------+----------------+-------------------------------+ | Benchmark | 38-master-full | 38-faster-meta | +=============================================================+================+===============================+ | read __module__ | 41.8 ns | 40.9 ns: 1.02x faster (-2%) | +-------------------------------------------------------------+----------------+-------------------------------+ | read __name__ | 41.8 ns | 39.9 ns: 1.05x faster (-5%) | +-------------------------------------------------------------+----------------+-------------------------------+ | read providedBy | 56.9 ns | 58.4 ns: 1.03x slower (+3%) | +-------------------------------------------------------------+----------------+-------------------------------+ | query adapter (no registrations) | 3.85 ms | 2.95 ms: 1.31x faster (-24%) | +-------------------------------------------------------------+----------------+-------------------------------+ | query adapter (all trivial registrations) | 4.62 ms | 3.63 ms: 1.27x faster (-21%) | +-------------------------------------------------------------+----------------+-------------------------------+ | query adapter (all trivial registrations, wide inheritance) | 51.8 us | 42.2 us: 1.23x faster (-19%) | +-------------------------------------------------------------+----------------+-------------------------------+ | query adapter (all trivial registrations, deep inheritance) | 52.0 us | 41.7 us: 1.25x faster (-20%) | +-------------------------------------------------------------+----------------+-------------------------------+ | sort interfaces | 234 us | 29.9 us: 7.84x faster (-87%) | +-------------------------------------------------------------+----------------+-------------------------------+ | sort mixed | 569 us | 340 us: 1.67x faster (-40%) | +-------------------------------------------------------------+----------------+-------------------------------+ | contains (empty dict) | 135 ns | 55.2 ns: 2.44x faster (-59%) | +-------------------------------------------------------------+----------------+-------------------------------+ | contains (populated dict: interfaces) | 137 ns | 56.1 ns: 2.45x faster (-59%) | +-------------------------------------------------------------+----------------+-------------------------------+ | contains (populated list: interfaces) | 39.7 us | 2.96 us: 13.42x faster (-93%) | +-------------------------------------------------------------+----------------+-------------------------------+ | contains (populated dict: implementedBy) | 137 ns | 55.2 ns: 2.48x faster (-60%) | +-------------------------------------------------------------+----------------+-------------------------------+ | contains (populated list: implementedBy) | 40.6 us | 24.1 us: 1.68x faster (-41%) | +-------------------------------------------------------------+----------------+-------------------------------+ Not significant (2): read __doc__; sort implementedBy
* Use a descriptor for __module__Jason Madden2020-03-184-48/+83
| | | | | | | | | | | | | | | | | | | | | | | | | | | This makes the rest of the attribute access fast again, but slows down __module__. +-------------------------------------------+------------+-------------------------------+ | Benchmark | 38-master3 | 38-faster-descr | +===========================================+============+===============================+ | read __module__ | 41.1 ns | 123 ns: 2.99x slower (+199%) | +-------------------------------------------+------------+-------------------------------+ | read __name__ | 41.3 ns | 39.9 ns: 1.04x faster (-3%) | +-------------------------------------------+------------+-------------------------------+ | read __doc__ | 41.8 ns | 42.4 ns: 1.01x slower (+1%) | +-------------------------------------------+------------+-------------------------------+ | query adapter (no registrations) | 3.85 ms | 2.95 ms: 1.30x faster (-23%) | +-------------------------------------------+------------+-------------------------------+ | query adapter (all trivial registrations) | 4.59 ms | 3.67 ms: 1.25x faster (-20%) | +-------------------------------------------+------------+-------------------------------+ | contains (empty dict) | 136 ns | 54.8 ns: 2.48x faster (-60%) | +-------------------------------------------+------------+-------------------------------+ | contains (populated dict) | 137 ns | 55.7 ns: 2.46x faster (-59%) | +-------------------------------------------+------------+-------------------------------+ | contains (populated list) | 40.2 us | 2.86 us: 14.03x faster (-93%) | +-------------------------------------------+------------+-------------------------------+ Not significant (1): read providedBy
* Avoid use of a metaclass by implementeng __getattribute__.Jason Madden2020-03-184-212/+221
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This is pretty, but it slows down all attribute access to interfaces. By up to 25%. I'm not sure that's acceptable for things like Interface.providedBy. +-------------------------------------------+------------+-------------------------------+ | Benchmark | 38-master3 | 38-faster3 | +===========================================+============+===============================+ | read __module__ | 41.1 ns | 44.3 ns: 1.08x slower (+8%) | +-------------------------------------------+------------+-------------------------------+ | read __name__ | 41.3 ns | 51.6 ns: 1.25x slower (+25%) | +-------------------------------------------+------------+-------------------------------+ | read __doc__ | 41.8 ns | 53.3 ns: 1.28x slower (+28%) | +-------------------------------------------+------------+-------------------------------+ | read providedBy | 56.7 ns | 71.6 ns: 1.26x slower (+26%) | +-------------------------------------------+------------+-------------------------------+ | query adapter (no registrations) | 3.85 ms | 2.95 ms: 1.31x faster (-23%) | +-------------------------------------------+------------+-------------------------------+ | query adapter (all trivial registrations) | 4.59 ms | 3.65 ms: 1.26x faster (-20%) | +-------------------------------------------+------------+-------------------------------+ | contains (empty dict) | 136 ns | 55.4 ns: 2.45x faster (-59%) | +-------------------------------------------+------------+-------------------------------+ | contains (populated dict) | 137 ns | 55.0 ns: 2.49x faster (-60%) | +-------------------------------------------+------------+-------------------------------+ | contains (populated list) | 40.2 us | 2.95 us: 13.62x faster (-93%) | +-------------------------------------------+------------+-------------------------------+
* Fix tests when zope.component is also importable.Jason Madden2020-03-182-1/+24
|
* Clean up linter errors in test_interface.py so new/real problems are more ↵Jason Madden2020-03-181-41/+52
| | | | obvious.
* Fix doctest by making sure the default type repr can be used.Jason Madden2020-03-181-2/+16
|
* Move Interface hashing and comparison to C; 2.5 to 15x speedup in micro ↵Jason Madden2020-03-184-74/+318
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | benchmarks Included benchmark numbers: Current master, Python 3.8: ..................... contains (empty dict): Mean +- std dev: 198 ns +- 5 ns ..................... contains (populated dict): Mean +- std dev: 197 ns +- 6 ns ..................... contains (populated list): Mean +- std dev: 53.1 us +- 1.2 us This code: ..................... contains (empty dict): Mean +- std dev: 77.9 ns +- 2.3 ns ..................... contains (populated dict): Mean +- std dev: 78.4 ns +- 3.1 ns ..................... contains (populated list): Mean +- std dev: 3.69 us +- 0.08 us So anywhere from 2.5 to 15x faster. Not sure how that will translate to larger benchmarks, but I'm hopeful. It turns out that messing with ``__module__`` is nasty, tricky business, especially when you do it from C. Everytime you define a new subclass, the descriptors that you set get overridden by the type machinery (PyType_Ready). I'm using a data descriptor and a meta class right now to avoid that but I'm not super happy with that and would like to find a better way. (At least, maybe the data part of the descriptor isn't necessary?) It may be needed to move more code into C, I don't want a slowdown accessing ``__module__`` either; copying around the standard PyGetSet or PyMember descriptors isn't enough because they don't work on the class object (so ``classImplements(InterfaceClass, IInterface)`` fails).
* Move the one-base optimization down a level, and enable using pre-calculated ↵Jason Madden2020-03-183-33/+84
| | | | | | | | __sro__ for caching. In my local 'load the world' test, this went from ~7800 full C3 merges to about ~1100. Also take steps to avoid triggering false positive warnings about changed ROs when it's *just* Interface that moved.
* Ensure Interface is the last item in the __sro__.Jason Madden2020-03-183-21/+131
| | | | | | None of the elegant solutions mentioned in the issue worked out, so I had to brute force it. Fixes #8
* Merge pull request #189 from zopefoundation/issue136-issue134Jason Madden2020-03-181-2/+2
|\ | | | | Documentation clarifications.
| * Documentation clarifications.issue136-issue134Jason Madden2020-03-171-2/+2
| | | | | | | | | | | | | | | | | | - docs/adapter.rst Subscriptions are returned from least to most specific, not the other way around; the docs were incorrect. Add additional examples, and use more verbose names in current examples, to clarify this. Fixes #136. - interfaces.py names() and namesAndDescriptions() just return a collection, not a sequence. Fixes #134.
* | More minor documentation fixups.issue190Jason Madden2020-03-181-12/+13
| | | | | | | | Mostly formatting. Some interfaces were being documented as clasess, which doesn't work.
* | Make Interface.getTaggedValue follow the __iro__.Jason Madden2020-03-183-28/+203
|/ | | | | | | | 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.
* Use C3 (mostly) to compute IRO.issue21Jason Madden2020-03-1515-54/+1001
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* Add additional low-level tests for super() unwrapping.Jason Madden2020-03-101-1/+38
|
* Remove unused str variablesJason Madden2020-03-101-15/+8
| | | | | The DEFINE_STRING macro prevents the linter from seeing them as unused so I temporarily redefined it to find all such variables.
* Make provided/implementedBy and adapter registries respect super().issue11Jason Madden2020-03-095-45/+647
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* Cleanups per review.issue138Jason Madden2020-02-175-41/+34
|
* Update documentation and clarify the relationship of the older mapping and ↵Jason Madden2020-02-177-49/+158
| | | | sequence interfaces.
* Do not test _WindowsConsoleIOJason Madden2020-02-171-1/+1
|
* Find more concrete classes that are registered.Jason Madden2020-02-175-15/+41
|
* Add interfaces for builtins and the io ABCs.Jason Madden2020-02-179-64/+439
|
* Add numbers ABC interfaces.Jason Madden2020-02-175-39/+199
|
* Add collections.IByteString and refactor to avoid one-to-one assumption ↵Jason Madden2020-02-173-45/+161
| | | | | | about ABCs and builtins. bytearray turns out to violate that.
* Add z.i.common.collections to parallel the collections.abc classes.Jason Madden2020-02-173-2/+482
| | | | | | | | Register implemented standard library types on import. Derive the interface methods and documentation from the ABC automatically. I hope to use this for numbers too. Part of #138
* Merge pull request #177 from zopefoundation/fix-signatureJens W. Klein2020-02-162-5/+5
|\ | | | | Fix repr of "Attribute" to look like before
| * Fix repr of "Attribute" to look like beforeJens W. Klein2020-02-162-5/+5
| | | | | | | | and as usual in Python.
* | Add test case for #6.issue6Jason Madden2020-02-141-1/+50
|/ | | | It seems to be working now, so this fixes #6
* Simplify the string formatting rules for the Invalid exceptions.Jason Madden2020-02-103-77/+221
| | | | | | As per review. Also include the actual failing implementation object in the BrokenMethodImplementation to make it easier to track down what's going on when inheritance is involved.
* Make verifyObject/Class collect and raise all errors instead of only the first.issue171Jason Madden2020-02-084-85/+247
| | | | Fixes #171.
* Add warning to change note about string changes breaking doctests.Jason Madden2020-02-082-7/+31
| | | | Also tweak documentation to DRY for verifyObject/verifyClass.
* Also document the not-a-method case.issue170Jason Madden2020-02-071-1/+1
|
* Make verification errors more readable and useful.Jason Madden2020-02-075-47/+180
| | | | | | | | | | | | | | 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
* Fix verification for methods of builtin types with pseudo-default arguments ↵issue118Jason Madden2020-02-066-46/+162
| | | | | | | | | on Pypy On PyPy2, they are ignored (like on CPython), but on PyPy3 they can actually be validated. Fixes #118
* Add __all__ to all modules.issue153Jason Madden2020-02-0510-39/+117
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* better namingJens W. Klein2020-02-041-9/+9
|
* iPerformace optimization in _lookup _lookupAll _subscriptionslookup-performanceJens W. Klein2020-02-041-6/+13
|
* The _empty singleton has no-op subscribe/unsubscribe methods.issue162Jason Madden2020-01-283-9/+43
| | | | | | | | 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.
* apply suggestion by @jmadden to enhance commentJens W. Klein2020-01-281-2/+2
|
* Remove unneeded overwrite and call to anyway inherited __hash__ methodhash_performance_2Jens W. Klein2020-01-281-3/+0
|
* Add comment detailing why __bases__ can be set per review.issue158Jason Madden2020-01-271-1/+7
|
* Make the singleton _empty immutable.Jason Madden2020-01-272-3/+101
| | | | Fixes #158
* Remove support for hashing uninitialized interfaces.issue157Jason Madden2020-01-272-17/+4
| | | | Fixes #157
* Whitespace.Jason Madden2020-01-271-1/+1
|
* Avoid allocating space for tagged values unless they're used. This saves ↵Jason Madden2020-01-271-3/+9
| | | | another few percent.