`configparser.RawConfigParser` stub does not account for non-string options
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 5.1k
- Forks
- 2.1k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 82
Descripción
The stub for configparser.RawConfigParser.set has its value argument typed as str | None (source) when it can accept lots of other types and is leading to a false positive in mypy for me.
Consider this valid script:
from configparser import RawConfigParser
cfg = RawConfigParser()
cfg.add_section("default")
cfg.set("default", "some_option1", True)
r1 = cfg.get("default", "some_option1")
print(r1, type(r1))
cfg.set("default", "some_option2", 1)
r2 = cfg.get("default", "some_option2")
print(r2, type(r2))
cfg.set("default", "some_option3", b"bytes")
r3 = cfg.get("default", "some_option3")
print(r3, type(r3))
It prints:
True <class 'bool'>
1 <class 'int'>
b'bytes' <class 'bytes'>
However, mypy flags this code for the reason described above:
test.py:6: error: Argument 3 to "set" of "RawConfigParser" has incompatible type "bool"; expected "Optional[str]"
test.py:11: error: Argument 3 to "set" of "RawConfigParser" has incompatible type "int"; expected "Optional[str]"
test.py:15: error: Argument 3 to "set" of "RawConfigParser" has incompatible type "bytes"; expected "Optional[str]"
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza con stdlib/configparser.pyi alrededor de la línea 133 y compara la firma de RawConfigParser.set con el comportamiento mostrado en el issue. Ejecuta el script proporcionado con mypy para reproducir los falsos positivos y, después, verifica que los valores booleanos, enteros y bytes se acepten sin errores, mientras que el comportamiento existente de get siga estando cubierto.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- tooling
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 68/100