You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import itertools
from typing import Any
from pydantic import BaseModel
class M(BaseModel):
x: Any
m = M(x=[1])
m.model_dump() # ok
m.model_dump_json() # ok
m = M(x=itertools.repeat(5))
m.model_dump() # ok
m.model_dump_json() # -> freeze
repeat(5) is an infinite iterator, what behavior are you expecting when doing m = M(x=itertools.repeat(5))? Pydantic could implement an iteration limit to avoid infinite loops but this is probably the responsibility of the developer.
@Viicos i try to define field that accept both list[int] and itertools.repeat and .model_dump returns original value without modification or unwraping infinity itertools.repeat
This example works(not freezing)
class M(BaseModel):
x: Iterable[int] | list[int]
but for M(x=[5]).model_dump() returns SerializationIterator
Initial Checks
Description
Hi!
Python freezes and not responding on Ctrl^C
How to fix this?
Thank you
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: