Skip to content

Disallow mutable defaults for fields #121

Description

@lyndsysimon

Current Behavior

If the value set for a field default is callable, it is called when the default is used. Else, the default value is effectively set to lambda: copy.deepcopy(<default>).

Calling copy.deepcopy on some values may have unexpected results, including a frame overflow if the object is recursively nested.

Desired Behavior

If the value set for a field default is callable, it is called when the default is used.
If the value is mutable, TypeError should be raised with a useful message.
Else, the default object should be used directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions