JSON numeric getters accept booleans as integers and floats

未關閉 適合新手
#935 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@pradeep-ramola 已經在處理了。

開始於 2026年11月30日。

  • #936 來自 @pradeep-ramola —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
78/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python

研究方向

從 JSON 解析節點實作中的 JsonParseNode.get_int_value() 和 get_float_value() 開始,接著追蹤具型別的原始值集合如何轉換每個元素。為直接值、由 JsonParseNodeFactory 解析的子節點,以及明確指定型別的集合新增回歸測試;保留布林 getter、有效的數值轉換,以及推斷出的布林集合。完成條件是布林值從數值 getter 回傳 None,且針對性的回歸測試與現有對照測試皆通過。

由索引模型根據 Issue 內容生成。

描述

Describe the bug

JsonParseNode.get_int_value() accepts JSON booleans as integers, and get_float_value() converts them to 1.0/0.0. This also occurs through child nodes parsed from JSON bytes and in explicitly typed numeric collections.

The implementation uses isinstance(value, int) / isinstance(value, (float, int)). In Python, bool is a subclass of int, but JSON booleans are not numeric tokens. Other non-number values already return None from these getters.

Reproduction

from kiota_serialization_json.json_parse_node import JsonParseNode
from kiota_serialization_json.json_parse_node_factory import JsonParseNodeFactory

print(JsonParseNode(True).get_int_value())       # True
print(JsonParseNode(False).get_float_value())    # 0.0
root = JsonParseNodeFactory().get_root_parse_node(
    "application/json", b'{"count": true}'
)
print(root.get_child_node("count").get_int_value())  # True
print(JsonParseNode([1, True, False, 0]).get_collection_of_primitive_values(float))
# [1.0, 1.0, 0.0, 0.0]

Expected behavior

Boolean inputs should follow the existing non-number path and return None from integer/float getters, rather than silently becoming numbers. Numeric collection conversion should use the same element conversion behavior it already uses for other non-numeric values. The actual boolean getter, valid integers/floats, integer-to-float conversion, and inferred boolean collections should remain unchanged.

This is not a request to redesign primitive collection nullability (#777), change public signatures, or change JSON writer behavior.

Environment and validation

  • Current main: ee58dcf.
  • Python 3.14.5, Windows; editable local JSON/abstractions packages.
  • Added scalar, real JSON factory/child, and typed collection regressions: 12 failures on unchanged source; focused run also has 20 passing controls/existing tests.
  • No production traffic or external API credentials involved.

Discovered through source review and reproduced locally with AI assistance. I can provide the focused parser fix and regression tests.

主要語言
Python
星號
31
分支
48
平均合併
16 小時 36 分鐘
30 天內合併 PR
73

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

microsoft/kiota-python 的其他 Issue

查看 microsoft/kiota-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。