Skip to content

Serializing mock.call objects raises an exception #1866

@davidhewitt

Description

@davidhewitt

The following code triggers a TypeError.

from unittest.mock import call
from pydantic_core import to_jsonable_python

# TypeError: '_Call' object cannot be converted to 'SchemaSerializer'
to_jsonable_python(call(1, 2, 3), fallback=lambda call: call.args)

We usually try very hard to avoid raising errors from serialization, this is also on a type inference pathway. I think it'd be reasonable to just hit fallback if the __pydantic_serializer__ attribute is invalid (this is the root cause of the TypeError).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions