Skip to main content

A naive implementation of C3 linearization algorithm used in Python's MRO

Project description

C3 Linearization Algorithm

c3linear is a naïve implementation of C3 linearization algorithm. C3 used in Python 2.3+ for Method Resolution Order. See Raymond Hettinger's Python’s super() considered super! for more information.

Motivation

The project has come to life as a byproduct of debugging an overcomplicated hierarchy of mixin classes. I thought I knew how exactly MRO is computed, but it turned out I didn't.

I've tried to keep the code idiomatic and easy to follow at the expense of performance. The project is really took a couple of hours to complete. Although I didn't care about time complexity and didn't check correctness as thoroughly as I should, I think the project may help someone who wants to learn how Python's Method Resolution Order works.

Usage

Library

  • Get the code and install it with python setup.py install (Python 3.6+ required)
  • Import from c3linear.mro import mro
  • Check against built-in MRO:
>>> class A: pass
>>> class B(A): pass
>>> mro(B) == B.mro()
True 

Take a look at tests for more examples.

Testing

  • Install dependencies:
pip install -e .
  • (Optional) Install extra packages:
pip install -e .[extra]
  • Run tests with:
python setup.py test
  • Run flake8 for PEP8 compliance testing:
python setup.py flake8
  • Run mypy:
mypy c3linear/

Contributing

If you've found a bug, please open an issue describing the problem first.

Licence

The project is licensed under MIT License. For further information see LINCENSE file.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for c3linear, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size c3linear-0.1.1-py3-none-any.whl (6.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size c3linear-0.1.1.tar.gz (4.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page