8000 Maxlen property always set to None, when deque item type is provided. · Issue #6581 · pydantic/pydantic · GitHub
[go: up one dir, main page]

Skip to content
Maxlen property always set to None, when deque item type is provided. #6581
@maciekglowka

Description

@maciekglowka

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

Selected Assignee: @davidhewitt

Metadata

Metadata

Assignees

Labels

bug V1Bug related to Pydantic V1.X

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0