Skip to content

ENH: Better API for collections instanciation  #73

Description

@OutSquareCapital

It's common to initialize mutable collections (dict, list) without elements, with the intention to mutate it later.

Rust approach this with constructors like BinaryHeap::new, Vec::new, or even iter::empty.

Python approach this with None checks in list, dict, set, etc... at runtime (or empty tuples as argument, need to check).

The former allow maximal performance and clarity of intent, while the second is the most convenient to type (and since dict and list can be written as literals, CPython can optimize this under the hood, bypassing the potential performance trade-off).

EDIT: see advancements on this issue on the comment below

  • We should check if there's a true speed difference between tuple default arg, None check, and MyCollection([]) calls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions