Skip to content
Discussion options

You must be logged in to vote

Ran the exact tutorial003_py310.py on fastapi 0.140.0 / pydantic 2.13.4 / py3.12 and it just works: item1 returns the car, item2 the plane with size, both 200, and the OpenAPI response schema comes out as anyOf of the two models. So the note is outdated. On 3.10+ PlaneItem | CarItem evaluates to a types.UnionType at runtime (PEP 604), which is exactly why passing it as the response_model value works.

The "must use Union, | would error" line is really pre-3.10 behavior, where SomeClass | OtherClass raises TypeError: unsupported operand type(s) for | (confirmed on 3.9.6). The example file itself got switched to the | form in the 3.10 typing-syntax upgrade, but the surrounding text stayed, s…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@Priyanshu-pulak
Comment options

Answer selected by Priyanshu-pulak
Comment options

You must be logged in to vote
1 reply
@Priyanshu-pulak
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
3 participants