Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a cell construtor, and expose the cell type in Lib/types.py #80092

Closed
pierreglaser mannequin opened this issue Feb 6, 2019 · 3 comments
Closed

add a cell construtor, and expose the cell type in Lib/types.py #80092

pierreglaser mannequin opened this issue Feb 6, 2019 · 3 comments
Labels
3.8 only security fixes type-feature A feature request or enhancement

Comments

@pierreglaser
Copy link
Mannequin

pierreglaser mannequin commented Feb 6, 2019

BPO 35911
Nosy @pitrou, @serhiy-storchaka, @1st1, @pierreglaser
PRs
  • bpo-35911: add cell constructor #11771
  • bpo-35911: add cell constructor #11771
  • Files
  • cell.patch
  • test_cell.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-02-07.19:37:16.139>
    created_at = <Date 2019-02-06.10:55:47.309>
    labels = ['type-feature', '3.8']
    title = 'add a cell construtor, and expose the cell type in Lib/types.py'
    updated_at = <Date 2019-02-07.19:37:16.138>
    user = 'https://github.com/pierreglaser'

    bugs.python.org fields:

    activity = <Date 2019-02-07.19:37:16.138>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-02-07.19:37:16.139>
    closer = 'pitrou'
    components = []
    creation = <Date 2019-02-06.10:55:47.309>
    creator = 'pierreglaser'
    dependencies = []
    files = ['48105', '48106']
    hgrepos = []
    issue_num = 35911
    keywords = ['patch']
    message_count = 3.0
    messages = ['334924', '334931', '335037']
    nosy_count = 4.0
    nosy_names = ['pitrou', 'serhiy.storchaka', 'yselivanov', 'pierreglaser']
    pr_nums = ['11771', '11771']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue35911'
    versions = ['Python 3.8']

    @pierreglaser
    Copy link
    Mannequin Author

    pierreglaser mannequin commented Feb 6, 2019

    cell objects are containers for the free variables of functions defined in a
    local scope. They are located in a function's __closure__ attribute (when
    it is not None). A cell is a very simple object, with a single (optional, e.g
    the cell can be empty) attribute: cell_contents.

    The C/Python API provides a constructor to create such objects (PyCell_New).
    However no cell.__new__ method is exposed to the pure python user. Workarounds
    exist, but are hacky, and involve the creation of intermediate, unused
    functions.

    Why would cell-creation be useful? because creating cells happens in pickle
    extensions modules designed to save user-defined functions and classes
    (https://github.com/cloudpipe/cloudpickle) (*). These moudules are dependencies of
    many widely-used data science frameworks (pyspark, ray, dask). Exposing a cell
    constructor will simplify theses extensions code base, and alleviate their
    maintenance cost.

    I propose to add and expose a simple cell constructor, that accepts 0 (empty
    cells) or 1 arguments. I also propose to expose the cell type in Lib/types.py
    (as types.CellType)

    (*): see related issues: https://bugs.python.org/issue35900

    @pierreglaser pierreglaser mannequin added 3.8 only security fixes type-feature A feature request or enhancement labels Feb 6, 2019
    @pitrou
    Copy link
    Member

    pitrou commented Feb 6, 2019

    Hi Pierre,

    You'll want to submit your patch as a GitHub pull request.
    Also your PR will have to contain:

    • tests for the new Python-facing API
    • documentation for the new API

    You may want to read more in the developer's guide:
    https://devguide.python.org/

    @pitrou
    Copy link
    Member

    pitrou commented Feb 7, 2019

    New changeset df8d2cd by Antoine Pitrou (Pierre Glaser) in branch 'master':
    bpo-35911: add cell constructor (GH-11771)
    df8d2cd

    @pitrou pitrou closed this as completed Feb 7, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.8 only security fixes type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant