Skip to content

Commit

Permalink
fix: Prevent alias resolution error when source-ordering members
Browse files Browse the repository at this point in the history
Issue griffe#213: mkdocstrings/griffe#213
  • Loading branch information
pawamoy committed Oct 5, 2023
1 parent b305634 commit 67df10c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/mkdocstrings_handlers/python/rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def _sort_key_alphabetical(item: CollectorItem) -> Any:

def _sort_key_source(item: CollectorItem) -> Any:
# if 'lineno' is none, the item will go to the start of the list.
if item.is_alias:
return item.alias_lineno if item.alias_lineno is not None else -1
return item.lineno if item.lineno is not None else -1


Expand Down
6 changes: 4 additions & 2 deletions tests/test_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ def test_ordering_members(order: rendering.Order, members_list: list[str | None]
"""

class Obj:
def __init__(self, name: str, lineno: int | None = None) -> None:
def __init__(self, name: str, lineno: int | None = None, *, is_alias: bool = False) -> None:
self.name = name
self.lineno = lineno
self.alias_lineno = lineno
self.is_alias = is_alias

members = [Obj("a", 10), Obj("b", 9), Obj("c", 8)]
members = [Obj("a", 10, is_alias=True), Obj("b", 9, is_alias=False), Obj("c", 8, is_alias=True)]
ordered = rendering.do_order_members(members, order, members_list) # type: ignore[arg-type]
assert [obj.name for obj in ordered] == expected_names

0 comments on commit 67df10c

Please sign in to comment.