JSON numeric getters accept booleans as integers and floats

Aberta Para iniciantes
#935 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@pradeep-ramola já está trabalhando nisso.

Desde 30/11/2026.

  • #936 de @pradeep-ramola — aberto

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
78/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
python

Direção de pesquisa

Comece com JsonParseNode.get_int_value() e get_float_value() na implementação do nó de análise JSON e, em seguida, acompanhe como as coleções primitivas tipadas convertem cada elemento. Adicione regressões para valores diretos, filhos analisados por JsonParseNodeFactory e coleções tipadas explicitamente; preserve os getters booleanos, as conversões numéricas válidas e as coleções booleanas inferidas. O trabalho estará concluído quando os booleanos retornarem None dos getters numéricos e as regressões focadas e os controles existentes passarem.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
Python
Estrelas
31
Forks
48
Merge médio
16h 36min
PRs com merge (30d)
73

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de microsoft/kiota-python

Todas as issues de microsoft/kiota-python

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.