Skip to content

Docs: unittest.mock.mock_open documents the wrong default for read_data #151443

@iamsharduld

Description

@iamsharduld

The documentation for unittest.mock.mock_open gives the signature as:

mock_open(mock=None, read_data=None)

but the actual default for read_data is the empty string, not None:

  • Lib/unittest/mock.py: def mock_open(mock=None, read_data=''):
  • The function's own docstring: "read_data is a string ... This is an empty string by default."
  • At runtime: inspect.signature(mock_open) returns (mock=None, read_data='')

The code default was changed from None to '' in 2012 (commit 0dccf657b51, "Minor changes to the unittest.mock.mock_open helper"), but the documented signature was never updated. The surrounding prose already describes read_data as "a string", so the None in the signature is stale and slightly misleading.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir
    No fields configured for issues without a type.

    Projects

    Status
    Done
    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions