Welcome to Msort’s documentation!

Msort is a python library for formatting python classes.

Msort can keep components of classes in a pre-defined order according to method names and decorators.

This can be useful for navigating complex classes, maintaining readability and, through the msort_group decorator, grouping directly related methods together.

Here is an example python class with three methods:

  • __init__()

  • func()

  • _private_func()

class ExampleClass:

  def _private_func(self):
     print("This is a private method!")

  def __init__(self):
     self.name: str = "example"

  def func(self):
     print("This is your average method!")

Running msort with default configurations would carry out two key changes to ExampleClass.

First, the methods would be re-ordered such that dunder methods come first, followed by the average method, func, followed by the private method _private_func.

Second, msort can automatically detect methods which could be made into a static method.

The result would be:

class ExampleClass:

  def __init__(self):
     self.name: str = "example"

  @staticmethod
  def func():
     print("This is your average method!")

  @staticmethod
  def _private_func():
     print("This is a private method!")

Contents

Indices and tables