-
-
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
Make stringify_annotation recursive on builtins with args #11570
Conversation
It seems there is a failing test:
I don't know if this is the intended behavior though. After all the result of |
The annotation is an annotation object, it's not necessarily a string (it shouldn't be one). If it's a "string-like" value, it should likely be a forward reference. In addition, I would like to see some tests with different values of |
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.
- Apply a similar logic to
restify
. - Add tests when you have more complex structures
list[tuple[A, ...]]
for instance (if it's not already the case) forstringify_annotation
andrestify
functions or when you have forward references.
Thanks for the quick review. I am not a sphinx expert, I just noticed this problem and I am trying to fix it.
If we are calling After all (if I am not mistaken) if we are calling
I am gonna try to add the tests. |
You are misunderstanding what
|
I've added more tests for both I've also corrected the test
instead of
|
Good. Can you do some visual checks for the HTML builder as well? just to be on the safe side (you can do them locally, no need to implement them) but just to be sure that the RST content produced can be properly converted into a "nice" visual. |
Can you also check that it works properly when guarded by |
There's already a test for that in What is giving me a headache instead are the two linter problems:
and
|
What I meant by testing with For the first error, it's likely that you are reusing a variable that has already a decided type. For the second error, it's because of You need: assert (stringify_annotation(Union[MyClass1, MyClass2], 'fully-qualified-except-typing') ==
"tests.test_util_typing.MyClass1 | tests.test_util_typing.<MyClass2>") to be assert (stringify_annotation(Union[MyClass1, MyClass2], 'fully-qualified-except-typing') ==
"tests.test_util_typing.MyClass1 | tests.test_util_typing.<MyClass2>") I think. Or maybe assert (stringify_annotation(Union[MyClass1, MyClass2], 'fully-qualified-except-typing') ==
"tests.test_util_typing.MyClass1 | tests.test_util_typing.<MyClass2>") |
Finally the CI for the linter passed! Whew, this took longer than it should have. Thanks @picnixz for the help. There is still a failing job, just for windows but it really seems unrelated to my changes. Moreover it seems on my fork of sphinx it's not failing https://github.com/patacca/sphinx/actions/runs/5822600118/job/15787579726 Regarding the html |
For the HTML TYPE_CHECKING test, you could do it similarly as in Anyway, could you also add a CHANGES entry? |
I added my line in CHANGES I tested the TYPE_CHECKING visual html like this (it's an extract from my project): from __future__ import annotations
from typing import TYPE_CHECKING
from abc import ABCMeta, abstractmethod
if TYPE_CHECKING:
from qbindiff.features.extractor import FeatureExtractor
class Visitor(metaclass=ABCMeta):
"""
Abstract class representing interface that a visitor
must implements to work with a Differ object.
"""
@property
@abstractmethod
def feature_extractors(self) -> list[FeatureExtractor]:
"""
Returns the list of registered features extractor
"""
# stuff It seems to be working correctly. Please tell me if there are other corrections to be made. |
It appears to me that it's fine. At least it appears that everything is clickable so it should be ok I think. |
Yes, I can confirm it is indeed clickable and pointing to the right URL |
Can you resolve the conflicts? |
I rebased on master |
@patacca -- for future reference, please create a PR from a named brach rather than master! A |
Thank you! I wonder if you might be interested into looking at another change -- now that generic alias types exist, it doesn't make much sense for Sphinx to output A |
I can try to do this. |
This is needed because of sphinx-doc/sphinx#11570
Subject: Make stringify_annotation recursive on builtins with args
Bugfix
Purpose
The current implementation of
stringify_annotation
in case of a builtin type with arguments is to just return the internal representation of the type (repr(annotation)
).With the following patch it is recursively calling itself on the arguments. This way it correctly displaying all the types.
Consider the following example:
The autodoc sphinx extension, even when
autodoc_typehints_format = "short"
, it is showing the fully qualified nameWhile instead with the following patch it is showing