bwhmather / ssort

Tool for automatically sorting python statements within a module
MIT License
360 stars 10 forks source link

No sorting for methods, properties etc. #101

Closed slafs closed 8 months ago

slafs commented 1 year ago

When having a file like this:

class Foo:
    # simple methods
    def foo2(self):
        return self.foo1()

    def foo1(self):
        return 1

    # property
    def foo_prop2(self):
        return self.foo_prop1

    @property
    def foo_prop1(self):
        return 2

    # classmethod
    def foo_classmethod2(self):
        return self.foo_classmethod1()

    @classmethod
    def foo_classmethod1(cls):
        return 3

    # staticmethod
    def foo_static2(self):
        return self.foo_static1()

    @staticmethod
    def foo_static1():
        return 4

and running ssort --diff on it,

ssort doesn't modify the file at all (1 file was left unchanged).

I'd expect that all members of Foo class with suffix 1 to be sorted in the way they appear before the respective ones with suffix 2.

Am I missing something? I thought ssort was handling such cases 🤔.

bwhmather commented 9 months ago

Sorry for slow response. ssort used to try to sort class methods and attributes topologically, but we found that this conflicted with automatic grouping based on type (attributes, constructors, special attributes, regular methods, etc) and so we stopped doing it.

At the file level, there aren't the same natural groups (except for maybe imports and if __name__ == "__main__":) and things tend to end up as graphs rather than a bag of methods that manipulate the same state.

bwhmather commented 9 months ago

(related discussion here: https://github.com/bwhmather/ssort/issues/11)

bwhmather commented 8 months ago

Closing as duplicate of #11