-
-
Notifications
You must be signed in to change notification settings - Fork 671
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
Custom type hint doc formatting for TypeAlias
, TypeVar
#2645
Conversation
1df4a8b
to
59feb63
Compare
else: | ||
# sphinx-autodoc-typehints errors when these are gated with TYPE_CHECKING... | ||
PositionT = None | ||
SizeT = None |
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.
Any idea why it only affects PositionT and SizeT, and not any of the other type aliases?
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.
I didn't look in to it too far yet....but I think it could be related to the circular import
It's a little unwieldy that we need to manually configure each type alias that we want to support, but the I can't argue with the end product - that's pretty much exactly what I had in mind. The only nitpick I'd have is that the fallback behavior looks like it's currently Even better would be to have a warning/error raised if there's a type alias that is falling back to this default. Having the docs actively complain if we don't document a new type alias will guarantee that we at least describe what the type means (and, in the case of StyleT, will force us to describe what that actually means). |
For |
13a5556 is an experiment with making each Specific to this effort, it makes it much easier to replace the existing type annotations in the docs using these The current use of But we can't do any of this if we want a But then...the real fun begins. If you dig in to how This became more and more of a mess the further I went with it...but I wanted to at least document it... |
@rmartin16 What do you consider the state of this experiment? Should we close this out, or leave it as a potential WIP? |
I'll clean it up this week and see if we want to merge it. There are inherent issues with identifying some of the TypeAliases; so, we may only be able to use this strategy for some of them. I can confirm which ones those are. |
13a5556
to
e4806df
Compare
I'm going to say this isn't really working. There are several issues. First, several of these TypeAliases don't exist at runtime since they are gated with And that's the second issue; you have to recreate some of these complicated type definitions to identify the correct annotation to replace. For several reasons, such as typing's forward references, this is less than straightforward and quite frustrating. Third, this hook is provided by I left the current state usable in case anyone wants to make their own attempt. |
Changes
TypeAlias
andTypeVar
TypeAlias
has already been resolved, so we need to match on the aliased typesThis POC is crude but what do you think about the idea?
sphinx-autodoc-typehints
produces....sans the unreadable aliases and type varsPR Checklist: