Biblioteca de prompts

Prompts de Python

Prompts para código Python: adicionar anotações de tipos, escrever suítes pytest e fazer profiling de funções lentas.

Os prompts estão em inglês, o idioma em que foram escritos e testados. As descrições e instruções destas páginas estão traduzidas.

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

Suíte pytest para uma função

Escreve testes pytest cobrindo casos normais, limites e erros de uma função que você fornecer.

Use quando: Uma função não tem testes e você quer cobertura de casos extremos antes de refatorá-la.

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>

Variáveis

{{function}}
O código-fonte da função, com seus imports.

Entrada de exemplo

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

Saída de exemplo

```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 a forma esperada, não gerada por um modelo.

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

Adicionar anotações de tipos a código Python

Adiciona anotações de tipos precisas que passam em um verificador de tipos estrito, sem mudar o comportamento.

Use quando: Ao ativar mypy ou pyright em um módulo sem tipos.

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>

Variáveis

{{module}}
O código-fonte Python a anotar.

Entrada de exemplo

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

Saída de exemplo

```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 a forma esperada, não gerada por um modelo.

Deixe com a sua cara

Edite os requisitos para seguir os seus padrões e depois verifique o resultado. O analisador de prompts o pontua de novo enquanto você digita, o otimizador remove enchimento sem perder nenhum requisito e o scanner de segurança sinaliza segredos e dados pessoais antes de você enviá-lo a um modelo.

Mais categorias