Avoid relying on `typing.TYPE_CHECKING` to the maximum possible extent
Nobody has claimed this yet.
- Dominant language
- Cython
- Stars
- 3.4k
- Forks
- 329
- Avg merge
- 1d 23h
- Merged PRs (30d)
- 116
Description
During investigation of #454 and related doc rendering issues, it has come to my attention that the type checking detection logic does not work well with Sphinx (ex: https://github.com/sphinx-doc/sphinx/issues/13137, https://github.com/sphinx-doc/sphinx/issues/11225).
Independently, Ralf has pointed out that it makes code debugging harder (https://github.com/NVIDIA/cuda-python/pull/463#discussion_r1967029167).
The idea of having a if TYPE_CHECKING: check is to avoid unnecessary imports or circular imports. If such issues do not exist, we should avoid using it.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the TYPE_CHECKING usage implicated by #454 and the related Sphinx issues, then identify which guards prevent unnecessary or circular imports. Check how those imports affect Sphinx rendering and debugging. Done means unnecessary TYPE_CHECKING guards are removed while guards needed for import safety remain.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- developer-experience, documentation
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 42/100