Examples is never formatted correctly

Open
#46 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
python
Domain
tooling

Research direction

Start with the embedded Python example and the reported pydantic_ai_slim/pydantic_ai/tools.py:103:1 location, then run the repository's formatting checks to reproduce the Ruff import-order failure. Identify why the example is transformed into that file and make the formatting tools agree; done means the example passes both formatting checks.

Written by the indexing model from the issue text.

Description

This example is never formatted correctly

from typing import Union

from pydantic_ai import RunContext, Tool
from pydantic_ai.tools import ToolDefinition

async def only_if_42(
    ctx: RunContext[int], tool_def: ToolDefinition
) -> Union[ToolDefinition, None]:
    if ctx.deps == 42:
        return tool_def

def hitchhiker(ctx: RunContext[int], answer: str) -> str:
    return f'{ctx.deps} {answer}'

hitchhiker = Tool(hitchhiker, prepare=only_if_42)

Because ruff and black disagree.

Black error:

ruff failed:
  pydantic_ai_slim/pydantic_ai/tools.py:103:1: I001 [*] Import block is un-sorted or un-formatted
    |
  1 | / from typing import Union
  2 | | 
  3 | | from pydantic_ai import RunContext, Tool
  4 | | from pydantic_ai.tools import ToolDefinition
  5 | | 
  6 | | async def only_if_42(
    | |_^ I001
  7 |       ctx: RunContext[int], tool_def: ToolDefinition
  8 |   ) -> Union[ToolDefinition, None]:
    |
    = help: Organize imports

  Found 1 error.
  [*] 1 fixable with the `--fix` option.
Dominant language
Python
Stars
181
Forks
29
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from pydantic/pytest-examples

All issues in pydantic/pytest-examples

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.