Declare supported types in the `use` type

未关闭
#4,579 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
48/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
python

调研方向

Start by reading the accessor types and the array_support table in docs/conf.py (lines 171–213), then compare them with the type hints, runtime checks, and tests for functions such as tl.rank_genes_groups and umap. Define how supported array types should be represented in accessor annotations and how the docs should consume those declarations. Done means support declarations live with function types and the documentation reflects them consistently.

由索引模型根据 Issue 内容生成。

描述

Triage 🩺
What kind of feature would you like to request?

Improved documentation or error message?

Please describe your wishes

Currently, which array types a function accepts is written down by hand in four places: the type hints, the array_support table in docs/conf.py, the array types each test picks, and a runtime check per function.

Apart from repeating code, these sometimes disagree. E.g., tl.rank_genes_groups runs on dask arrays and its test includes dask, but the conf.py table does not mention dask.

This gets more complicated with the recent accessoring, since use is typed as RepAcc which in turn translates to LayerAcc | MultiAcc. Thus, it is currently impossible to declare something like "this function only accepts accessors pointing to numpy or dask arrays" when following the established documentation patterns.

Instead of this, a few variants of RepAcc could provide the necessary documentation both in the code as well as for the docs directly. Example:

type RepInMemory = Annotated[LayerAcc | MultiAcc, ArraySupport("np", "sp")]
type RepLazy = Annotated[LayerAcc | MultiAcc, ArraySupport("np", "sp", "da", "xp")]
type RepGraphInMemory = Annotated[GraphAcc, ArraySupport("np", "sp")]

def umap(adata, *, use: RepGraphInMemory | str | None = None, rep: RepInMemory | str | None = None): ...

This would at least move the support declarations into the types of the functions and out of conf.py, which should make it easier for both humans and agents to see what is supported.

Nonetheless, this would not be enforcable on its own and would thus only be a first step. The next step might be to base runtime checks and test cases on this.

Ideally, it would be possible to declare the type an accessor would need to point to and have that be type-checked, but with the current accessor design in AnnData, I do not know how full typing could be implemented. So, the above would be my suggestion for now until full type checking becomes possible.

Please let me know if this is of interest and I can PR it.

主要语言
Python
星标
2.6k
派生
809
平均合并
1 天 1 小时
30 天内合并 PR
79

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

scverse/scanpy 的其他 Issue

查看 scverse/scanpy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。