Metadata-Version: 2.4
Name: reverse-lookup
Version: 1.0.0
Summary: Implementation of reversed lookup allowing classes to decide when to allow control to its subclasses
Author-email: Matias David Szlajen <matiasszlajen@tutamail.com>
License-Expression: MIT
Project-URL: Repository, https://github.com/Mszlajen/python-reverse-lookup
Keywords: metaprogramming,lookup,mro,classes
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# Reverse Lookup

Implementation of a reverse lookup similar to [Beta](https://beta.cs.au.dk/) where parent classes have priority and decide when to allow the subclasses (or the instance) to extend its behaviour.

## Installation

Reverse Lookup is made using pure python metaprogamming interfaces so it can be installed easily from pypi

```bash
python -m pip install reverse_lookup
```

## Usage

Using Reverse Lookup is as simple as inhereting a class.

```python
from reverse_lookup import ReverseLookup

class A(ReverseLookup):
    ...
```

Now all instances of `A` will have a lookup that looks like `object -> A -> <A object>`.  
This works for subclasses too.

```python
class A(ReverseLookup):
    def m(self):
        return 'A'

class B(A):
    def m(self):
        return 'B'

B().m() # => 'A'
```

To allow subclasses to extend the logic you can use `Inner`.

```python
from reverse_lookup import ReverseLookup, Inner

class A(ReverseLookup):
    def m(self):
        return 'A' + Inner(self, A).m()
        
class B(A):
    def m(self):
        return 'B'

B().m() #=> 'AB'
```

Like the built-in `super`, `Inner` can be send any message and it will do a lookup for it starting at the step following the class recived as parameter in the mro, it will fail with `AttributeError` if there is not a next implementation and special methods need to be called explicitly.

Since python doesn't allow monkey patching of standard classes (ex. object), special method such as `__str__ ` still use the all lookup.

## Motivation

We mentioned ina class that this was posible using metaprogramming and I though it was a fun project.
