-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use the obj role for all See Also items #8051
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d9fb3bc
search the role for See Also items in the intersphinx inventory
keewis e697242
fix the tests by falling back to a empty dict on AttributeError
keewis ca0bd28
ignore the mypy error on possibly failing attribute lookup
keewis 4428393
translate the functions before attempting to find a matching role
keewis 95c861f
always use :obj: instead of searching the inventory
keewis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1151,6 +1151,41 @@ def push_item(name: str, rest: List[str]) -> None: | |
items.append((name, list(rest), role)) | ||
del rest[:] | ||
|
||
def search_inventory(inventory, name, hint=None): | ||
roles = list(inventory.keys()) | ||
if hint is not None: | ||
preferred = [ | ||
role | ||
for role in roles | ||
if role.split(":", 1)[-1].startswith(hint) | ||
] | ||
roles = preferred + [role for role in roles if role not in preferred] | ||
|
||
for role in roles: | ||
objects = inventory[role] | ||
found = objects.get(name, None) | ||
if found is not None: | ||
domain, role = role.split(":", 1) | ||
return role | ||
|
||
return None | ||
|
||
def translate(func, description, role): | ||
translations = self._config.napoleon_type_aliases | ||
if role is not None or not translations: | ||
return func, description, role | ||
|
||
translated = translations.get(func, func) | ||
match = self._name_rgx.match(translated) | ||
if not match: | ||
return translated, description, role | ||
|
||
groups = match.groupdict() | ||
role = groups["role"] | ||
new_func = groups["name"] or groups["name2"] | ||
|
||
return new_func, description, role | ||
|
||
current_func = None | ||
rest = [] # type: List[str] | ||
|
||
|
@@ -1181,37 +1216,20 @@ def push_item(name: str, rest: List[str]) -> None: | |
if not items: | ||
return [] | ||
|
||
roles = { | ||
'method': 'meth', | ||
'meth': 'meth', | ||
'function': 'func', | ||
'func': 'func', | ||
'class': 'class', | ||
'exception': 'exc', | ||
'exc': 'exc', | ||
'object': 'obj', | ||
'obj': 'obj', | ||
'module': 'mod', | ||
'mod': 'mod', | ||
'data': 'data', | ||
'constant': 'const', | ||
'const': 'const', | ||
'attribute': 'attr', | ||
'attr': 'attr' | ||
} | ||
if self._what is None: | ||
func_role = 'obj' | ||
else: | ||
func_role = roles.get(self._what, '') | ||
# apply type aliases | ||
items = [ | ||
translate(func, description, role) | ||
for func, description, role in items | ||
] | ||
|
||
func_role = 'obj' | ||
lines = [] # type: List[str] | ||
last_had_desc = True | ||
for func, desc, role in items: | ||
if role: | ||
link = ':%s:`%s`' % (role, func) | ||
elif func_role: | ||
link = ':%s:`%s`' % (func_role, func) | ||
else: | ||
link = "`%s`_" % func | ||
link = ':%s:`%s`' % (func_role, func) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems |
||
if desc or last_had_desc: | ||
lines += [''] | ||
lines += [link] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is no longer needed now.