Skip to content

Commit 44b9223

Browse files
pkazmierkernc
authored andcommitted
ENH: Sort subclasses for cross-platform consistency (#128)
* Sort subclasses for cross-platform consistency The sort order for subclasses is inconsistent between platforms. As a result, projects that include generated docs in their repos see diffs to the generated files based on the platform of the contributor. This adds an explicit sort so we have a deterministic order of subclasses. * Change intrinsic sort order to use refname This will sort classes using their fully qualified names.
1 parent 3a5e1d1 commit 44b9223

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pdoc/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def _inherits_top(self):
476476
return top
477477

478478
def __lt__(self, other):
479-
return self.name < other.name
479+
return self.refname < other.refname
480480

481481

482482
class Module(Doc):
@@ -882,8 +882,8 @@ def subclasses(self) -> List['Class']:
882882
The objects in the list are of type `pdoc.Class` if available,
883883
and `pdoc.External` otherwise.
884884
"""
885-
return [self.module.find_class(c)
886-
for c in type.__subclasses__(self.obj)]
885+
return sorted(self.module.find_class(c)
886+
for c in type.__subclasses__(self.obj))
887887

888888
def params(self, *, annotate=False, link=None) -> List['str']:
889889
"""

pdoc/test/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,11 +568,22 @@ class C(A):
568568
class D(B):
569569
pass
570570

571+
class G(C):
572+
pass
573+
574+
class F(C):
575+
pass
576+
577+
class E(C):
578+
pass
579+
571580
mod = pdoc.Module(pdoc)
572581
self.assertEqual([x.refname for x in pdoc.Class('A', mod, A).subclasses()],
573582
[mod.find_class(C).refname])
574583
self.assertEqual([x.refname for x in pdoc.Class('B', mod, B).subclasses()],
575584
[mod.find_class(D).refname])
585+
self.assertEqual([x.refname for x in pdoc.Class('C', mod, C).subclasses()],
586+
[mod.find_class(x).refname for x in (E, F, G)])
576587

577588
def test_link_inheritance(self):
578589
mod = pdoc.Module(EXAMPLE_MODULE)

0 commit comments

Comments
 (0)