python / python/typeshed

Semaphore's value argument

Abierto
#12,147 3 comentarios 0 reacciones 0 asignados Ver en GitHub

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

Currently we assume that the semaphore's value must be an integer:
https://github.com/python/typeshed/blob/1af9de664f41b51bd3b71dac349564c5c25df810/stdlib/asyncio/locks.pyi#L88-L93

Generally this is correct, but I had a use case where I wanted to disable the semaphore without restructuring my code, so I used float("inf") as the value to ensure that it never unlocks. This works perfectly fine, because the only operations that value needs to support are:

  • Adding 1
  • Subtracting 1
  • Comparing to 0

The infinity float value does all of these fine. So I therefore wonder if we should make this type be int | Literal[math.inf]? I agree that general floats are not a good idea because they will get below 0 without triggering the wait.

Guía de contribución

Abrir la guía de contribución

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.

Línea de trabajo

Comienza con stdlib/asyncio/locks.pyi en las líneas 88-93 e inspecciona la anotación del valor de Semaphore y las convenciones de typeshed circundantes. Confirma si int | Literal[math.inf] expresa el comportamiento compatible y, después, ejecuta la validación relevante de typeshed; se considera terminado cuando la anotación acepta infinity sin ampliar la compatibilidad a floats generales.

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

Evaluación

Stack tecnológico
python
Área
devtools
Tipo de issue
Nueva funcionalidad
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.