-
Notifications
You must be signed in to change notification settings - Fork 133
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
Add support for type aliases introduced in Python 3.12 via PEP 695 #414
Comments
Hello, I do not have exactly the same issue, as luckily my code base only use types declared with the However, such declared types are rendered as plain text: no "unwrapping" of the nested types like done before, nor a link to a potential type definition I am not sure if this is a problem on A suggestion: add a "Types" section that summarizes the type definitions. In function signatures, add links to the type definition. We can even push further and imagine having a tooltip like in IDEs displaying information about the type Example of code using type PuzzleInput = list[tuple[list[str], int]]
type HandAndBid = tuple[list[int], int]
type PuzzleMappedInput = list[HandAndBid]
type SortedByHandType = dict[Any, list[HandAndBid]]
@dataclass(kw_only=True)
class AdventOfCodeProblem202307(AdventOfCodeProblem[PuzzleInput]):
year: int = 2023
day: int = 7
def solve_part_1(self, puzzle_input: PuzzleInput): ... When hovering
When hovering
|
Just noting that this is currently blocked due to the lack of a way to document type aliases in Sphinx (sphinx-doc/sphinx#7896). astroid already has support for parsing type aliases. |
It seems that implementing type aliases in Sphinx is going to take some time. In the meantime, I've pushed a commit that will workaround the limitation by rendering PEP-695 |
Sphinx 7.4.0 introduced this feature so we should now be able to proceed with proper type alias support. |
Hi,
I've started updating my codebases to Python 3.12, including adding type aliases via
type CustomType = dict[str, int] | list[int]
and sharing them across files viafrom src.module import CustomType
. The code itself works fine, but building the documentation does not:Cannot resolve import of src.module.CustomType in src.other_module
Since I use warnings-as-errors by default, this currently breaks all my documentation builds. Setting
suppress_warnings = ["autoapi"]
does get rid of the warning.There might be a correlated issue in sphinx-doc/sphinx#11561.
I'm also not quite sure how these type aliases are supposed to be documented and opened a discussion on python.org, but this does not resolve the import issues.
The text was updated successfully, but these errors were encountered: