Skip to content

mock.seal changes behavior of isinstance for generic classes #139152

@torfsen

Description

@torfsen

Bug report

Bug description:

from unittest.mock import Mock, seal

class Foo:
    pass

class Bar[T]:
    pass

for cls in [Foo, Bar]:
    print(cls.__name__, "unsealed:", isinstance(Mock(cls), cls))

    m = Mock(cls)
    seal(m)
    print(cls.__name__, "sealed:", isinstance(m, Foo))

With both Python 3.12.7 and 3.13.7 this prints

Foo unsealed: True
Foo sealed: True
Bar unsealed: True
Bar sealed: False

I would have expected that sealing a mock does not change its behavior w.r.t. isinstance.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions