Skip to content

defaultdict setdefault method not using the default_factory initializer parameter #141752

@MarcoPeli

Description

@MarcoPeli

Bug report

Bug description:

test = defaultdict(set) #sets default factory method
test['ok'].add(1) # this is ok
test.setdefault('not_ok') # this should use the default factory method, dry principle
test['not_ok'].add(1) # error here, NoneType doesn't have add method :(

_ = test['ok2'] # this is a workaround to add a key using default factory

CPython versions tested on:

3.12

Operating systems tested on:

Windows

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