Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

doclets: Allow overloaded functions to not conflict #111

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion sphinx_js/doclets.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def gather_doclets(app):
doclet_full_path(d, root_for_relative_paths),
d)
except PathTaken as conflict:
conflicts.append(conflict.segments)
# Allow overloaded functions, but not other duplicates
if d['kind'] != 'function':
conflicts.append(conflict.segments)
if conflicts:
raise PathsTaken(conflicts)

Expand Down
16 changes: 15 additions & 1 deletion tests/test_build_ts/source/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,18 @@ class ClassDefinition {
anotherMethod() {

}
}

/**
* This is an overloaded method (1).
*/
overloaded(arg: number): number;

/**
* This is an overloaded method (2).
*/
overloaded(arg: string): string;

overloaded(arg: number | string): number | string {
return arg;
}
}
7 changes: 7 additions & 0 deletions tests/test_build_ts/test_build_ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ def test_autoclass_star_order(self):
pos_field = contents.index('ClassDefinition.field')
pos_method2 = contents.index('ClassDefinition.anotherMethod')
assert pos_method < pos_field < pos_method2, 'Methods and fields are not in right order in ' + contents

def test_overloads(self):
"""Make sure overloaded methods work."""
contents = self._file_contents('index')
pos_overloaded_1 = contents.index('overloaded method (1)')
pos_overloaded_2 = contents.index('overloaded method (2)')
assert pos_overloaded_1 < pos_overloaded_2, 'Method overloads are not in right order in ' + contents