Skip to content

Examples is never formatted correctly #46

Open
@samuelcolvin

Description

@samuelcolvin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions