Skip to content

Inconsistent type annotation for serializer context #11844

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

Open
1 task done
devon-mar opened this issue May 5, 2025 · 1 comment
Open
1 task done

Inconsistent type annotation for serializer context #11844

devon-mar opened this issue May 5, 2025 · 1 comment
Assignees
Labels
bug V2 Bug related to Pydantic V2
Milestone

Comments

@devon-mar
Copy link

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

In BaseModel.model_dump, context has the type annotation Any | None:

context: Any | None = None,

but in TypeAdapter.dump_python, context has the type annotation dict[str, Any] | None (passing something that is not a dict seems to work):

context: dict[str, Any] | None = None,

In the example in the docs, context is a dict: https://docs.pydantic.dev/latest/concepts/serialization/#serialization-context so I'd assume that the context parameter of BaseModel.model_dump should also be dict[str, Any]?

Example Code

Python, Pydantic & OS Version

pydantic version: 2.10.6
        pydantic-core version: 2.27.2
          pydantic-core build: profile=release pgo=false
                 install path: <project>/.venv/lib/python3.12/site-packages/pydantic
               python version: 3.12.8 (main, Jan 14 2025, 22:49:14) [Clang 19.1.6 ]
                     platform: Linux-5.15.167.4-microsoft-standard-WSL2-x86_64-with-glibc2.40
             related packages: typing_extensions-4.12.2 mypy-1.14.1
                       commit: unknown
@devon-mar devon-mar added bug V2 Bug related to Pydantic V2 pending Is unconfirmed labels May 5, 2025
@Viicos
Copy link
Member

Viicos commented May 5, 2025

I think we should type hint as Any. I'll probably handle this as part of pydantic/pydantic-core#1686.

@Viicos Viicos removed the pending Is unconfirmed label May 5, 2025
@Viicos Viicos self-assigned this May 5, 2025
@Viicos Viicos added this to the v2.12 milestone May 5, 2025
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
Projects
None yet
Development

No branches or pull requests

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy