-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Fix rendering of nested type annotations with alias defined #9736
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
base: master
Are you sure you want to change the base?
Conversation
The current implementation replaces type annotations with a alias defined by the class TypeAliasForwardRef. This class is later again replaced by the type defined in the alias map. This commit fixes the problem that this second replacement does not happen if the aliased type is nested in another generic type (e.g. Iterator[aliased_type]). The new function goes recursivly through the nested types and replaces the internal class TypeAliasForwardRef again by the correct annotation.
cc9a185
to
d8c202f
Compare
I've been getting the error (side question: is it possible to tell autodoc to just completely not try to make type hints into cross-references?) |
This makes Sphinx read the type hints directly. It also triggers a Sphinx bug that requires this Sphinx PR to fix sphinx-doc/sphinx#9736.
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.
Please add a testcase for this implementation.
@@ -614,6 +614,17 @@ def _should_unwrap(subject: Callable) -> bool: | |||
return False | |||
|
|||
|
|||
def _fix_type_alias_forward_ref(annotation: Any) -> Any: |
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.
How about expand_type_alias_forward_ref()
instead?
Additonally, it would be better to add a docstring to this.
|
||
if hasattr(annotation, "__args__"): 8000 | ||
new_args = tuple(_fix_type_alias_forward_ref(arg) for arg in annotation.__args__) | ||
return annotation.copy_with(new_args) |
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.
Is this method available on python3.6 and 3.10?
Subject: Fix rendering of nested type annotations with alias defined
Feature or Bugfix
Purpose
Detail
The current implementation replaces type annotations with a alias defined by the class TypeAliasForwardRef. This class is later again replaced by the type defined in the alias map.
This commit fixes the problem that this second replacement does not happen if the aliased type is nested in another generic type (e.g. Iterator[aliased_type]). The new function goes recursivly through the nested types and replaces the internal class TypeAliasForwardRef again by the correct annotation.
Relates