Biblioteca de prompts

Prompts de Python

Prompts para código Python: añadir anotaciones de tipos, escribir suites de pytest y perfilar funciones lentas.

Los prompts están en inglés, el idioma en que se escribieron y probaron. Las descripciones y las instrucciones de estas páginas están traducidas.

  • pytest
  • testing
  • python
100/100 · 139 tokens

Suite de pytest para una función

Escribe pruebas de pytest que cubren casos normales, límites y errores para una función que proporciones.

Úsalo cuando: Una función no tiene pruebas y quieres cobertura de casos límite antes de refactorizarla.

prompt
You are a senior Python engineer writing tests with pytest.

## Task
Write a pytest test module for the function below.

## Requirements
- Cover one normal case, every boundary value, and every exception the function raises.
- Use pytest.mark.parametrize where 3 or more cases share one assertion.
- Name each test test_<function>_<condition>_<expected result>.
- Use only pytest and the standard library.
- Do not test behavior the function does not implement.

## Output format
Return one Python code block containing the complete test module, followed by a bulleted list of any behavior in the function that looks like a bug.

## Input
<function>
{{function}}
</function>

Variables

{{function}}
El código fuente de la función, con sus importaciones.

Entrada de ejemplo

function: def parse_duration(text: str) -> int, which converts "1h30m" to seconds and raises ValueError on bad input.

Salida de ejemplo

```python
@pytest.mark.parametrize("text, expected", [("1h", 3600), ("30m", 1800), ("1h30m", 5400)])
def test_parse_duration_valid_returns_seconds(text, expected):
    assert parse_duration(text) == expected
```
- `parse_duration("")` returns 0 instead of raising ValueError.

Ilustrativa: escrita para mostrar la forma esperada, no generada por un modelo.

  • type hints
  • mypy
  • python
100/100 · 150 tokens

Añadir anotaciones de tipos a código Python

Añade anotaciones de tipos precisas que pasan un verificador de tipos estricto, sin cambiar el comportamiento.

Úsalo cuando: Al activar mypy o pyright en un módulo sin tipar.

prompt
You are a senior Python engineer adding type hints for a strict type checker.

## Task
Add type hints to the Python module below so it passes mypy in strict mode.

## Requirements
- Do not change runtime behavior, names, or signatures beyond adding annotations.
- Never use Any; use object, a Protocol, or a TypeVar where the type varies.
- Use built-in generics such as list[str] and the X | None syntax.
- Use a TypedDict or dataclass for every dictionary with fixed keys.

## Output format
Return one Python code block containing the annotated module, followed by a bulleted list of every annotation you were unsure of and what you assumed.

## Input
<module>
{{module}}
</module>

Variables

{{module}}
El código fuente Python que anotar.

Entrada de ejemplo

module: a functions file with def load_users(path) that returns a list of dicts with name and email.

Salida de ejemplo

```python
class User(TypedDict):
    name: str
    email: str

def load_users(path: str | Path) -> list[User]: ...
```
- `path`: assumed to accept both str and Path, as it is passed to open().

Ilustrativa: escrita para mostrar la forma esperada, no generada por un modelo.

Hazlo tuyo

Edita los requisitos para que se ajusten a tus estándares y revisa el resultado. El analizador de prompts vuelve a puntuarlo mientras escribes, el optimizador elimina el relleno sin perder ningún requisito y el escáner de seguridad marca secretos y datos personales antes de que lo envíes a un modelo.

Más categorías