Skip to main content

demi - de-multiple-inheritance; squash class inheritance

Did you make a mistake in designing a mess of classes with multiple inheritance everywhere?

Do you want to understand deeply nested class hierarchies without navigating many different source code files?

Will you avoid making such mistakes in the future?

... well, my answers to the above questions are "yes :(", "yes!", and "probably not", respectively.

In any case -

This repo is a proof-of-concept of a tool that may have the potential to help with the above. It probably won't help you just yet.

Requirements

  • Python 3.9+ (for ast.unparse)

Usage

Install

$ pip install demi

Try with a provided test class:

$ demi import demi.tests.cls_ab.C

Or preferrably, reformat with black at the same time:

$ demi import demi.tests.cls_ab.C |black -
class C:
    """A Docstring

    B Docstring

    C Docstring"""

    a_value = "A"

    def afunc(self) -> str:
        return "A"

    def superfunc(self) -> int:
        def _super_A() -> int:
            b = ord(self.afunc())
            a = b + 2
            return a

        return _super_A() + 1

    b_value = "B"
    c_value = "C"

    def bfunc(self) -> str:
        return "B"

    def cfunc(self) -> str:
        return "C"

Or maybe try something from the standard library:

demi import argparse.BooleanOptionalAction
demi import tkinter.Widget
...

Maybe TODO

  • Properties have the same name twice, so only the setter gets shown
  • Switch to redbaron to retain comments?
  • Automatically invoke black to reformat the output?
  • Test suite?
  • For returns at the end of the method, simplify code?
  • Consider astor for Python below 3.9?

Metadata

Release files for demi 0.0.0

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

Source distribution (sdist)

Source distribution for demi 0.0.0
File Size Uploaded
demi-0.0.0.tar.gz 32.5 kB Details

Release files / demi-0.0.0.tar.gz

Download URL demi-0.0.0.tar.gz
Size 32.5 kB
Tags Source
SHA-256 checksum
How to use checksums
36e2c9b4568a59e8656e45b130cb16407f31669e8a0abcd7900ba7e4957885d1
BLAKE2b-256 checksum
How to use checksums
089c7b33e8a5ddf43c31413ab8a6ec1adac2b74a22c6cb639fd28a035b42a102
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.0.0 This release

1 release file

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