sorted-attributes¶
Ever wanted to sort a bunch of class attributes alphabetically? Well now it’s easy! Just add “@sorted-attributes” in the doc string of a class definition and lint will automatically sort all attributes alphabetically.
Feel free to add other methods and such – it should only affect class attributes.
Message¶
It appears you are using the @sorted-attributes directive and the class variables are unsorted. See the lint autofix suggestion.
Valid examples¶
class MyConstants:
"""
@sorted-attributes
"""
A = 'zzz123'
B = 'aaa234'
class MyUnsortedConstants:
B = 'aaa234'
A = 'zzz123'
Invalid examples¶
class MyUnsortedConstants:
"""
@sorted-attributes
"""
z = "hehehe"
B = 'aaa234'
A = 'zzz123'
cab = "foo bar"
Daaa = "banana"
@classmethod
def get_foo(cls) -> str:
return "some random thing"
Suggested fix
class MyUnsortedConstants:
"""
@sorted-attributes
"""
A = 'zzz123'
B = 'aaa234'
Daaa = "banana"
cab = "foo bar"
z = "hehehe"
@classmethod
def get_foo(cls) -> str:
return "some random thing"