Skip to content

Allow setting cell value #74671

Description

@pitrou
BPO 30486
Nosy @rhettinger, @terryjreedy, @ncoghlan, @pitrou, @vstinner, @benjaminp, @serhiy-storchaka, @lisroach, @DimitrisJim
PRs
  • bpo-30486: Allow setting cell value #1840
  • bpo-30486: Make cell_set_contents() symbol private #3668
  • 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 = 'https://github.com/lisroach'
    closed_at = <Date 2017-06-08.11:45:01.119>
    created_at = <Date 2017-05-26.16:17:01.425>
    labels = ['interpreter-core', 'type-feature', '3.7']
    title = 'Allow setting cell value'
    updated_at = <Date 2017-09-20.13:54:17.955>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2017-09-20.13:54:17.955>
    actor = 'vstinner'
    assignee = 'lisroach'
    closed = True
    closed_date = <Date 2017-06-08.11:45:01.119>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2017-05-26.16:17:01.425>
    creator = 'pitrou'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 30486
    keywords = []
    message_count = 10.0
    messages = ['294554', '294573', '294577', '294583', '295057', '295058', '295416', '295417', '295476', '302617']
    nosy_count = 9.0
    nosy_names = ['rhettinger', 'terry.reedy', 'ncoghlan', 'pitrou', 'vstinner', 'benjamin.peterson', 'serhiy.storchaka', 'lisroach', 'Jim Fasarakis-Hilliard']
    pr_nums = ['1840', '3668']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue30486'
    versions = ['Python 3.7']

    Activity

    1. pitrou commented on May 26, 2017

      @pitrou
      MemberAuthor

      There are use cases for setting a cell value. One such use case is for (un)pickling recursive closures (see heroic workaround here: https://github.com/cloudpipe/cloudpickle/pull/90/files#diff-d2a3618afedd4e124c532151eedbae09R74 ). Other use cases may include tinkering around and general education value.

      There also doesn't seem to be, AFAICS, any counter-indication to being able to do so. It's already possible in C using PyCell_Set(), which is a public API. It just lacks an API in Python land. For example cell_contents could become a read/write property...

    2. lisroach commented on May 27, 2017

      @lisroach
      Contributor

      This idea makes sense to me. I'll see if I can put together the code for it.

    3. rhettinger commented on May 27, 2017

      @rhettinger
      Contributor

      +1 I don't see any reason this can't be writeable.

    4. ncoghlan commented on May 27, 2017

      @ncoghlan
      Contributor

      +1 from me, as this also has potential value in testing use cases and in dealing with some of the consequences of the zero-arg super() design (i.e. it will make the injected __class__ cell writable)

    5. terryjreedy commented on Jun 2, 2017

      @terryjreedy
      Member

      A possible counter-indication would be if setting a cell could cause a crash, as opposed to a mysterious exception. Since 3.x already allows writing any object to a cell from python code,

      def outer():
      cell = None
      def inner(ob):
      nonlocal cell
      cell = ob # rebinds <hidden-cell>.cell_contents
      return inner

      set_cell = outer()
      print(set_cell.__closure__[0].cell_contents)  # None
      set_cell('something')
      print(set_cell.__closure__[0].cell_contents)  # 'something'

      making "cell.cell_contents = 'something'" legal should not enable more crashes.

      I think that "function.__closure__[i].cell_contents = object" is perhaps not a good idea for production code, but I think it falls within the realm of 'consenting adults code' for the other uses suggested above. How should it be documented?

    6. pitrou commented on Jun 2, 2017

      @pitrou
      MemberAuthor

      There's already a documentation change to the PR, you can leave your comments there.

    7. serhiy-storchaka commented on Jun 8, 2017

      @serhiy-storchaka
      Member

      New changeset 64505a1 by Serhiy Storchaka (Lisa Roach) in branch 'master':
      bpo-30486: Allow setting cell value (bpo-1840)
      64505a1

    8. serhiy-storchaka commented on Jun 8, 2017

      @serhiy-storchaka
      Member

      Thank you for your contribution Lisa!

    9. lisroach commented on Jun 9, 2017

      @lisroach
      Contributor

      Thank you for you guidance, Serhiy!

      On Thu, Jun 8, 2017 at 4:45 AM, Serhiy Storchaka <report@bugs.python.org>
      wrote:

      Serhiy Storchaka added the comment:

      Thank you for your contribution Lisa!

      ----------
      resolution: -> fixed
      stage: patch review -> resolved
      status: open -> closed


      Python tracker <report@bugs.python.org>
      <http://bugs.python.org/issue30486\>


    10. vstinner commented on Sep 20, 2017

      @vstinner
      Member

      New changeset 0ad05c3 by Victor Stinner in branch 'master':
      bpo-30486: Make cell_set_contents() symbol private (bpo-3668)
      0ad05c3

    11. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    3.7 (EOL)end of lifeinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions