Skip to content

unittest.mock: Regression with create_autospec and dataclasses in 3.14.0b2 #135368

Closed
@cdce8p

Description

@cdce8p

Bug report

Bug description:

from dataclasses import dataclass
from unittest.mock import create_autospec

@dataclass
class Description:
    name: str

mock = create_autospec(Description, instance=True)
print(isinstance(mock, Description))
# 3.13.3
True

# 3.14.0b2
False

Furthermore the resulting mock doesn't have attributes present on a dataclass instance, like __annotations__, __class__, __dataclass_fields__, __dataclass_params__.

print(dir(mock))
print(dir(Description("Hello World"))

Likely related to #124429. /CC @sobolevn

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

Labels

3.14bugs and security fixes3.15new features, bugs and security fixesstdlibPython modules in the Lib dirtopic-dataclassestype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions