JSON numeric getters accept booleans as integers and floats

オープン 初心者向け
#935 コメント 0 件 リアクション 0 件 担当者 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分
マージ済み PR(30日)
73

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/kiota-python のほかの issue

microsoft/kiota-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。