Skip to content

Pydantic Plugin: Add support for Annotated with Field constraints #14

@genro

Description

@genro

Feature Request

Add support for Pydantic's Annotated type with Field constraints in the Pydantic plugin.

Current State

The MVP implementation (v0.6.0) supports:

  • Basic types (str, int, float, bool)
  • Optional and default values
  • Complex types (List, Dict, Set, Tuple)
  • Existing Pydantic BaseModel instances

Requested Enhancement

Support Annotated with Field for constraints like:

from typing import Annotated
from pydantic import Field

sw = Switcher().plug("pydantic")

@sw
def create_user(
    name: Annotated[str, Field(min_length=2, max_length=50)],
    age: Annotated[int, Field(ge=0, le=120)],
    email: Annotated[str, Field(pattern=r'^[\w\.-]+@[\w\.-]+\.\w+$')]
):
    ...

Implementation Notes

  • Extract Field metadata from Annotated types
  • Pass constraints to dynamic Pydantic model creation
  • Ensure error messages show which constraint was violated

Priority

Medium - This would make the plugin more powerful for data validation use cases.

Related

Part of the Pydantic plugin MVP+1 features discussed in initial implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions