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 摘要。