Skip to main content

Sort the order of class functions and properties

Project description

seating

Sort the order of class functions, properties, and member variables.

Installation

Install with:

pip install seating

Sorting and Priority

  • Class variables declared in class body outside of a function
  • Dunder methods
  • Functions decorated with property or corresponding .setter and .deleter methods
  • Class functions

Each of these groups will be sorted alphabetically with respect to themselves.

The only exception is for dunder methods.
They will be sorted alphabetically except that __init__ will be first.

If you have class contents that are grouped a certain way and you want the groups individually sorted so that the grouping is maintained, you can use # Seat to demarcate the groups.

i.e. if the source is:

class MyClass():
    {arbitrary lines of code}
    # Seat
    {more arbitrary code}
    # Seat
    {yet more code}

then the three sets of code in brackets will be sorted independently from one another.

Usage

CLI

>seat -h
usage: seat [-h] [--start START] [--stop STOP] [-nb] [-o OUTPUT] [-d] file

positional arguments:
  file                  The file to format.

options:
  -h, --help            show this help message and exit
  --start START         Optional line number to start formatting at.
  --stop STOP           Optional line number to stop formatting at.
  -nb, --noblack        Don't format file with Black after sorting.
  -o OUTPUT, --output OUTPUT
                        Write changes to this file, otherwise changes are written back to the original file.
  -d, --dump            Dump ast tree to file instead of doing anything else. For debugging purposes.

Programmatically

from seating import seat
from pathier import Pathier

file = Pathier("somefile.py")
source = file.read_text()
source = seat(source)
file.write_text(source)

Project details


Download files

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

Source Distribution

seating-0.0.3.tar.gz (5.1 kB view hashes)

Uploaded Source

Built Distribution

seating-0.0.3-py3-none-any.whl (6.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page