Skip to content

[Recommendation]: Don't mess around with builtins, that's what modules are for :) #96

Closed
@rwgk

Description

@rwgk

Problem description

The title is by @Yhg1s, I'm just the messenger here.

We happened to stumble over this in connection with pybind11, then I looked in nanobind and see that's also adding capsules to builtins:

int rv = PyDict_SetItemString(PyEval_GetBuiltins(), NB_INTERNALS_ID, capsule);

Thomas wrote:

  • pybind11 should use a separate module for this instead.
  • messing with builtins is going to have some undesireable performance effects in the future.
  • If you want per-interpreter state that's easily accessible, just stuff a container object into sys.modules.

Reproducible example code

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions