graphql-python / graphql-python/graphql-core-legacy
Usage of Asserts Breaks Code
- Lenguaje dominante
- Python
- Estrellas
- 372
- Forks
- 175
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
This project uses asserts in a lot of places (I found about 100 cases) where they should **not** be used. They're being used to validate arguments to functions, where the normal Python way would be to use a `TypeError` or a `ValueError`. Assertions are essentially debug code, not code for validating arguments.
Any usage of optimize mode or Python (`-O` or `-OO`, or `PYTHONOPTIMIZE`) strips out assertions, making this code useless. That's very problematic if you're generating schema dynamically, as you won't get errors and this library will generate an invalid GraphQL schema.
At this point it's probably too late to change the uses of assert to a proper `TypeError` or `ValueError`, without a major version bump as dependent code in other projects may be catching `AssertionError`.
I'm proposing all instances of `assert foo, "Error"` be replaced with:
```python
if not foo:
raise AssertionError("Error") # Should be a TypeError
```
This will at least make the code work in optimize modes where assertions are stripped.
I'll gladly make a PR doing so, but it's hard to tell if this project is still actively developed.
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Busca en el repositorio los aproximadamente 100 usos de assert para la validación de argumentos descritos en el issue y compara su comportamiento con la ejecución normal y con la ejecución de Python -O. Revisa cada sitio de llamada afectado para comprobar su mensaje de error esperado y confirma que la ejecución optimizada siga rechazando las entradas no válidas sin cambiar la compatibilidad existente con AssertionError.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- graphql, python
- Área
- backend-api-design
- Tipo de issue
- Error
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100