pydantic / pydantic-extra-types

Extra Pydantic types.
MIT License
205 stars 54 forks source link

Pydantic does not support contextlib.ExitStack. #187

Open theunkn0wn1 opened 8 months ago

theunkn0wn1 commented 8 months ago

Initial Checks

Description

Pydantic does not allow contextlib.ExitStack nor contextlib.AsyncExitStack in models.

As I am using Pydantic in the context of FastAPI, using a Pydantic type for internal (non-user-facing) types was my first thought, as im already using it for user-facing components.

Example Code

from contextlib import ExitStack
from pydantic import BaseModel
class Demo(BaseModel):
    stack: ExitStack

Python, Pydantic & OS Version

pydantic version: 2.6.4
        pydantic-core version: 2.16.3
          pydantic-core build: profile=release pgo=true
                 install path: PATH_EXPUNGED/lib/python3.10/site-packages/pydantic
               python version: 3.10.11 (main, Apr 20 2023, 14:14:57) [GCC 9.4.0]
                     platform: Linux-6.5.0-18-generic-x86_64-with-glibc2.35
             related packages: fastapi-0.110.0 pydantic-settings-2.2.1 typing_extensions-4.10.0
                       commit: unknown
sydney-runkle commented 8 months ago

@theunkn0wn1,

I think this is a valid feature request. Marked it as such!