Skip to content

Fix the seal() example in the unittest.mock docs - #162234

Open
AlexxRussell wants to merge 1 commit into
python:mainfrom
AlexxRussell:doc-mock-seal
Open

AlexxRussell wants to merge 1 commit into
python:mainfrom
AlexxRussell:doc-mock-seal

Conversation

@AlexxRussell

Copy link
Copy Markdown

In the seal() example, mock.not_submock = mock.Mock(name="sample_name") calls Mock as an attribute of the mock that is about to be sealed, so not_submock is one of its children and gets sealed as well. The last line, commented "This won't raise", then raises AttributeError.

Using Mock(name="sample_name") makes the example behave as described.

Trivial docs fix, so no issue.

@python-cla-bot

python-cla-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35993057 | 📁 Comparing 50ab2c7 against main (ddd88c7)

  🔍 Preview build  

1 file changed
± library/unittest.mock.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant