> For the complete documentation index, see [llms.txt](https://edward-stevinson.gitbook.io/tech-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://edward-stevinson.gitbook.io/tech-notes/python/concepts.md).

# Concepts

## Mixins

A *mixin* is a special kind of multiple inheritance which is mainly used in one of the following two cases:

1. You want to provide a lot of optional features to a class.
2. You want to use one particular feature in a lot of different classes,

Essentially they encapsulate behaviour that can be reused in other classes. The difference from a parent class is that a mixim is independent enough. They are not generally used on their own but are not abstract classes either.

## Testing

### Monkey Patching

This is the dynamic replacement of attributes at runtime. This means you can replace a method that has external dependencies with a stub that returns some fixed data.

### Fixturees

Reusable code that is used to inject a test.

```
@pytest.fixture
```

### Mocks

### Dunder Methods

1. `__set_name__(self, owner, name)`

This can be used to access the variable name programatically. i.e. let descriptor class know the name of the property it is being used for.

1. `__get__(se;f, isntance, owner)`

This can be used to tell a manager class what other **instance** it is responsible for.

1. `__repr__(self)`

Returns the object representation.

1. `__class__()`

Descriptor object.

1. `__name__(self)`
2. `__mro__()`

method resolution order. A tuple of the class and all it's base classes, in order of inheritence.

1. `__get_attribute__(self, name)`
2. `__init__subclass__()`

This method is called whenever the containing class is subclassed. `cls` is then the new subclass. i.e. let the parent know when it is being subclassed.
