Skip to main content
Interfaces
==========

Overview
--------

This library is a trivial implementation of an interface in Python,
with the following aspects / features:

* It fails at import time, not at construction, so you know
immediately when you have a problem.
* It's quite simple (very few LOC) and lenient where it counts
* It exclusively uses decorators, so...
* It does not require inheritance (reducing 'forced' subclassing)
* It does not enforce any typing checks
* It is intended to 'enhance' duck typing by avoiding common
pitfalls (forgot to implement something on your fake duck class,
overwrote something fundamental, etc.)

Usage
-----

Given a simple interface like:

```python
@interfaces.define
class DuckInterface(object):

@interfaces.require
def quack(self):
"""All Ducks must implement a 'quack' method."""
pass
```

...the following will raise a MissingRequiredAttribute exception
at import time:

```python
@interfaces.define(object)
class Silent(object):
# no quack method
pass
```

This, however works:

```python
@interfaces.implement(DuckInterface)
class Tree(object):

@interfaces.final
def quack(self):
return "the tree appears to quack."

tree = Tree()
tree.quack()
```

Additionally, if you are interested in using the `final` method decorator
outside of an interface, you can do so using the `strict` class decorator
around any class you want to check:

```python
@interfaces.strict
class BaseClass(object):

@interfaces.final
class method(self):
return "Old functionality!"

# the following will raise an exception at import:

@interfaces.strict
class SubClass(object):

class method(self):
return "New functionality!"
```

Limitations
-----------

Obviously, this does nothing for enforcing interfaces on the calling side.
I've contemplated something like:

```python
def get_json(instance):
# raises an exception if instance does not implement
# JSONViewInterface
interfaces.expects(instance, JSONViewInterface)
return instance.to_json()
```

...but that may be too close to type checking, and the only thing you gain
is a more explicit exception at
runtime. Feedback welcome.


Metadata

Release files for interfaces 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for interfaces 0.0.2
File Size Uploaded Provenance
interfaces-0.0.2.tar.gz 3.3 kB Without provenance Details

Release files / interfaces-0.0.2.tar.gz

Download URL interfaces-0.0.2.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ba6cef161fac11870e87662f9386cb075e52fbef30532ea50e32dc4f11af2823
BLAKE2b-256 checksum
How to use checksums
3e8722232606bab94cd4248a9eeb10773c50e6409d2e7ed398f5cb970ba4c2d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for interfaces 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page