Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested Literals together with PEP-695 type statement are failed to produce json schema #9269

Open
1 task done
AlexanderPodorov opened this issue Apr 17, 2024 · 2 comments
Labels
bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation

Comments

@AlexanderPodorov
Copy link

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

See example code

Example Code

from typing import Literal

from pydantic import BaseModel

type TestType0 = Literal["test1", "test2"]
type TestType1 = Literal[TestType0, Literal["test3"]]
type TestType2 = Literal[Literal["test1", "test2"], Literal["test3"]]


# TestType1 does not work
# TestType2 works
class Model(BaseModel):
    f: TestType1


print(Model.model_json_schema())

Python, Pydantic & OS Version

pydantic version: 2.7.0
        pydantic-core version: 2.18.1
          pydantic-core build: profile=release pgo=true
               python version: 3.12.3 (v3.12.3:f6650f9ad7, Apr  9 2024, 08:18:47) [Clang 13.0.0 (clang-1300.0.29.30)]
                     platform: macOS-13.0.1-arm64-arm-64bit
             related packages: typing_extensions-4.11.0 fastapi-0.110.1 pydantic-extra-types-2.6.0 pydantic-settings-2.2.1
                       commit: unknown
@AlexanderPodorov AlexanderPodorov added bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation labels Apr 17, 2024
@sydney-runkle
Copy link
Member

@AlexanderPodorov,

Thanks for the report. Seems like we don't fully support this syntax yet - PRs welcome with added support!

@sydney-runkle
Copy link
Member

I don't think this is new as of 2.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V2 Bug related to Pydantic V2 pending Awaiting a response / confirmation
Projects
None yet
Development

No branches or pull requests

2 participants