-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Closed
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X
Description
Initial Checks
- I have searched GitHub for a duplicate issue and I'm sure this is something new
- I have searched Google & StackOverflow for a solution and couldn't find anything
- I have read and followed the docs and still think this is a bug
- I am confident that the issue is with pydantic (not my code, or another library in the ecosystem like FastAPI or mypy)
Description
The maxlen
property of the deque
field seems to be set to None
when the queue item type is provided.
In the example below I first create an untyped deque and upon instancing everything goes well - the maxlen
is set to 15
.
However when the model definitions is more specific: deque[int]
or Deque[int]
then the maxlen
value cannot be set.
Example Code
>>> from pydantic import BaseModel
>>> from collections import deque
>>> class D(BaseModel):
... q: deque = deque(maxlen=10)
...
>>> d = D(q=deque(maxlen=15))
>>> d
D(q=deque([], maxlen=15))
>>>
>>>
>>> class DI(BaseModel):
... q: deque[int] = deque(maxlen=10)
...
>>> d = DI(q=deque(maxlen=15))
>>> d
DI(q=deque([]))
>>>
>>> from typing import Deque
>>>
>>> class DT(BaseModel):
... q: Deque[int] = deque(maxlen=10)
...
>>> d = DT(q=deque(maxlen=15))
>>> d
DT(q=deque([]))
Python, Pydantic & OS Version
pydantic version: 1.10.5
pydantic compiled: True
install path: /opt/venv/lib/python3.11/site-packages/pydantic
python version: 3.11.4 (main, Jun 13 2023, 15:08:32) [GCC 10.2.1 20210110]
platform: Linux-5.15.90.1-microsoft-standard-WSL2-x86_64-with-glibc2.31
optional deps. installed: ['typing-extensions']
Affected Components
- Compatibility between releases
- Data validation/parsing
- Data serialization -
.dict()
and.json()
- JSON Schema
- Dataclasses
- Model Config
- Field Types - adding or changing a particular data type
- Function validation decorator
- Generic Models
- Other Model behaviour -
construct()
, pickling, private attributes, ORM mode - Plugins and integration with other tools - mypy, FastAPI, python-devtools, Hypothesis, VS Code, PyCharm, etc.
Selected Assignee: @davidhewitt
pydantic-hooky
Metadata
Metadata
Assignees
Labels
bug V1Bug related to Pydantic V1.XBug related to Pydantic V1.X