Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Keys method with (dotted=True) gives multiplication of the same key

Abierto
#237 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
52/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
python
Área
backend

Línea de trabajo

Comienza en el punto de entrada Box.keys(dotted=True) y reproduce el ejemplo del issue, comparando las rutas devueltas para mappings y valores de lista. Rastrea por qué los elementos de las listas producen rutas indexadas y, después, verifica que el resultado contenga únicamente las claves padre: Animals.Land_animals, Animals.Sea_animals y Trees.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

wontfix

Bug of keys in Box:

When you use keys() method in a "dotted" situation, meaning we have a tree of keys in a Box, and you want to get the keys of a given node, one can notice that we get back a list of keys that are multiplicated if the value of a key is a list. (and the multiplication is by the lengh of the list)

For example:

 

b = Box({
"Animals" : {"Land_animals" : ["Lion", "Elephant"], "Sea_animals" : ["Dolphin", "Shark"]},
"Trees" : ["Palm_tree", "Coconut_tree"]
}, box_dots = True)

 

When you are using keys = b.keys(dotted = True) you get -

['Animals.Land_animals[0]',
'Animals.Land_animals[1]',
'Animals.Sea_animals[0]',
'Animals.Sea_animals[1]',
'Trees[0]',
'Trees[1]']

and we can see the multiple occurances of the keys (with indexes of their number of values), and the method len(keys) would have wrong answer - 6 instead of 3.

The output which I thought would be right is: ['Animals.Land_animals', 'Animals.Sea_animals', 'Trees']

 

A workaround is to add to the box this:

box_intact_types = (tuple,list)

so that lists wouldn't be converted, and than it works fine.

Lenguaje dominante
Python
Estrellas
2.8k
Forks
145
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de cdgriffith/Box

Todos los issues de cdgriffith/Box

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.