Assertion and checking functions
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 25/100
- Issue 類型
- 功能
- 描述清晰度
- 需要釐清
- 活躍度
- 停滯
- 技術堆疊
- python, typescript
- 領域
- compilers
研究方向
從連結的 TypeScript 3.7 assertion-functions 文件以及 issue 中的 assert_positive 和 is_positive 範例開始。由於沒有指定 repository 檔案或測試,首先定義通用斷言和檢查註解應如何表達型別縮窄,然後記錄已達成共識的行為和所需的測試涵蓋範圍。
由索引模型根據 Issue 內容生成。
描述
I'll just leave this here for potential future consideration as it came up on gitter's typing-dev channel. Typescript has something called assertion functions, which enables the type checker to understand that a function does not return if a certain condition is false. I think something similar, but more generalized, would be interesting, especially for unit test functions like assert_is_instance(), assert_true() etc.
def assert_positive(x: object) -> AssertsInstance["x", int]:
assert isinstance(x, int) and x > 0
Related, checking functions could work like this:
def is_positive(x: object) -> ChecksInstance["x", int]:
return isinstance(x, int) and x > 0
def my_func(x: Union[int, str]) -> None:
if is_positive(x):
# x must be an int
...
else:
# x can be an int or str
...
- 主要語言
- Python
- 星號
- 1.8k
- 分支
- 302
- 平均合併
- 20 小時 26 分鐘
- 30 天內合併 PR
- 10
環境準備
我們還沒有檢查這個專案的環境設定檔。先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
python/typing 的其他 Issue
-
topic: typing spec
難度 2/5 1-3 小時 新手友好度 72/100
python/typing#2356 · 2 則留言 · 1 個 reaction ·
維護者通常 1 天內回覆
-
topic: typing spec
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 1 天內回覆
-
topic: documentation
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
topic: documentation
難度 2/5 1-3 小時 新手友好度 65/100
python/typing#2150 · 2 則留言 · 2 個 reaction ·
維護者通常 1 天內回覆
-
topic: conformance tests topic: typing spec
難度 3/5 1-2 天 新手友好度 72/100
維護者通常 1 天內回覆
相似的 Issue
-
docs pydanty:is-working
難度 2/5 1-3 小時 新手友好度 75/100
pydantic/pydantic-ai#8863 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
run-llama/llama_index#23278 ·
維護者通常 2 天內回覆
-
documentation from-review-extraction github-actions priority: low severity:nit
難度 1/5 1 小時以內 新手友好度 92/100
LearningCircuit/local-deep-research#6946 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 82/100
oracle/langchain-oracle#323 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
tenstorrent/tt-metal#58057 · 1 則留言 ·
維護者通常 1 天內回覆