Prompt-Bibliothek

Python-Prompts

Prompts für Python-Code: Typhinweise hinzufügen, pytest-Suiten schreiben und langsame Funktionen profilieren.

Die Prompts sind auf Englisch, der Sprache, in der sie geschrieben und getestet wurden. Beschreibungen und Hinweise auf diesen Seiten sind übersetzt.

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

pytest-Suite für eine Funktion

Schreibt pytest-Tests für Normalfälle, Grenzen und Fehler einer von Ihnen gelieferten Funktion.

Einsetzen, wenn: Eine Funktion hat keine Tests und Sie wollen Randfälle abgedeckt haben, bevor Sie sie refaktorieren.

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>

Variablen

{{function}}
Der Quellcode der Funktion mit ihren Importen.

Beispieleingabe

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

Beispielausgabe

```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.

Beispielhaft: geschrieben, um die erwartete Form zu zeigen, nicht von einem Modell erzeugt.

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

Typhinweise zu Python-Code hinzufügen

Fügt präzise Typhinweise hinzu, die einen strengen Typprüfer bestehen, ohne das Verhalten zu ändern.

Einsetzen, wenn: Beim Aktivieren von mypy oder pyright für ein untypisiertes Modul.

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>

Variablen

{{module}}
Der zu annotierende Python-Quellcode.

Beispieleingabe

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

Beispielausgabe

```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().

Beispielhaft: geschrieben, um die erwartete Form zu zeigen, nicht von einem Modell erzeugt.

Machen Sie ihn zu Ihrem

Passen Sie die Anforderungen an Ihre Standards an und prüfen Sie dann das Ergebnis. Der Prompt-Analyzer bewertet neu, während Sie tippen, der Optimierer entfernt Füllwörter, ohne eine Anforderung zu verlieren, und der Sicherheitsscanner markiert Geheimnisse und personenbezogene Daten, bevor Sie den Prompt an ein Modell senden.

Weitere Kategorien