Finalize sorting of class bodies
See original GitHub issueBefore sorting topologically, ssort
currently pre-sorts class members in the following order:
- Docstring.
- Special attributes (
__slots__
and__doc__
). - Regular class attributes.
- Lifecycle d’under methods (e.g.
__init__
or__del__
) in fixed order. - Regular methods in original order.
- All other d’under methods, in fixed order.
I think this is basically sensible but, unlike topological sorting of top-level statements, there is no strong argument for it to be this way.
I’d like to invite comments or opinions on how this order could be improved before the 1.0 release.
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
bwhmather/ssort: Tool for automatically sorting python ...
Tool for automatically sorting python statements within a module - GitHub ... ssort will sort top level statements and statements in class bodies....
Read more >Why I have access to finalize() method in other sub class of ...
When the finalize() method is called (because a System.gc() has been requested), the method will first be looked for in the SubClass class,...
Read more >Scripting API: SortingGroup - Unity - Manual
The SortingGroup component solves this by ensuring the entire branch of the character are sorted and rendered together.
Read more >Learn Java Programming - The Finalize Method Tutorial
In my Garbage Collection tutorial, I discussed how Java uses the garbage collector to free up memory on the heap. Objects are stored...
Read more >How To Sort An Array In Java - Tutorial With Examples
The sort method provided by 'java.util.Arrays' class is a very simple and faster way to sort an array. This method can sort elements...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I quite like @AnonymouX47’s order, it’s not dissimilar to ours and makes sense to my brain, but yeah, it’s likely to be a very personal preference for most users.
The fact is… no matter how much deliberation happens, the group order chosen will be opinionated in one way or the other.
So, I propose that a reasonable default order be chosen but beyond that, a user should be able to customize the grouping and group ordering as desired and even (maybe later) be able to include user-defined groups and change the group a statement belongs to.
So,
ssort
can define a default set of groups and a default group ordering for top-level statements and class members separately.For the custom group ordering, there could be:
For the addition of custom groups and to change the group a statement belongs:
A statement can belong to only one group.
The particularly-styled comment can be of the form:
for custom group ordering
and
for custom grouping. If
<group>
isn’t among the default, then it’s added to the set of groups for that module or class.