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

Make the property doctstring writeable #68252

Closed
rhettinger opened this issue Apr 27, 2015 · 11 comments
Closed

Make the property doctstring writeable #68252

rhettinger opened this issue Apr 27, 2015 · 11 comments
Assignees
Labels
easy interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@rhettinger
Copy link
Contributor

BPO 24064
Nosy @rhettinger, @ethanfurman, @berkerpeksag, @serhiy-storchaka
Files
  • issue24064.diff
  • property_clear.diff
  • 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/rhettinger'
    closed_at = <Date 2015-05-13.18:14:33.125>
    created_at = <Date 2015-04-27.04:53:07.289>
    labels = ['interpreter-core', 'easy', 'type-feature']
    title = 'Make the property doctstring writeable'
    updated_at = <Date 2015-05-15.23:17:12.668>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2015-05-15.23:17:12.668>
    actor = 'python-dev'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2015-05-13.18:14:33.125>
    closer = 'rhettinger'
    components = ['Interpreter Core']
    creation = <Date 2015-04-27.04:53:07.289>
    creator = 'rhettinger'
    dependencies = []
    files = ['39214', '39356']
    hgrepos = []
    issue_num = 24064
    keywords = ['patch', 'easy']
    message_count = 11.0
    messages = ['242098', '242107', '242334', '243048', '243050', '243054', '243062', '243077', '243079', '243111', '243286']
    nosy_count = 6.0
    nosy_names = ['rhettinger', 'cvrebert', 'ethan.furman', 'python-dev', 'berker.peksag', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue24064'
    versions = ['Python 3.5']

    @rhettinger
    Copy link
    Contributor Author

    I can't see any reason for property docstrings to be readonly:

        >>> p = property(doc='basic')
        >>> p.__doc__
        'basic'
        >>> p.__doc__ = 'extended'
        Traceback (most recent call last):
          File "<pyshell#46>", line 1, in <module>
            p.__doc__ = 'extended'
        AttributeError: readonly attribute

    Among other things, making it writeable would simplify the ability to update the docstrings produced by namedtuple;

        Time.mtime.__doc__ = 'modification time'
        Score.max = 'all time cumulative high score for a single season'

    @rhettinger rhettinger added interpreter-core (Objects, Python, Grammar, and Parser dirs) easy type-feature A feature request or enhancement labels Apr 27, 2015
    @berkerpeksag
    Copy link
    Member

    Here is a patch. I'm not familiar with this part of the CPython source. So please tell me if there is a better way to do it. I only updated Doc/whatsnew/3.5, but other places in the documentation needs to be updated.

    @serhiy-storchaka
    Copy link
    Member

    If make docstrings writable, it would be good to ensure that they exactly are strings. And if make the property doctstring writable, may be make other docstrings writable? It may be useful for setting the same docstring for Python implementation and C accelerator.

    @rhettinger
    Copy link
    Contributor Author

    If make docstrings writable, it would be good to ensure
    that they exactly are strings.

    I don't see a need for this restriction. Even regular classes don't enforce this.

    @rhettinger rhettinger self-assigned this May 13, 2015
    @serhiy-storchaka
    Copy link
    Member

    Perhaps the property class now need set the tp_clear slot?

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 13, 2015

    New changeset 1e8a768fa0a5 by Raymond Hettinger in branch 'default':
    Issue bpo-24064: Property() docstrings are now writeable.
    https://hg.python.org/cpython/rev/1e8a768fa0a5

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 13, 2015

    New changeset bde652ae05fd by Berker Peksag in branch 'default':
    Issue bpo-24064: Add __doc__ to the example in collections.rst.
    https://hg.python.org/cpython/rev/bde652ae05fd

    @serhiy-storchaka
    Copy link
    Member

    LGTM.

    @serhiy-storchaka
    Copy link
    Member

    An example of uncollectable loop if tp_clear is not implemented:

    class A:
        @property
        def f(self): pass
    
    A.f.__doc__ = (A.f,)

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 13, 2015

    New changeset 2ddadd0e736d by Raymond Hettinger in branch 'default':
    Issue bpo-24064: Help property() support GC
    https://hg.python.org/cpython/rev/2ddadd0e736d

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 15, 2015

    New changeset 5262dd507ee5 by Raymond Hettinger in branch 'default':
    Issue bpo-24064: Docuement that oroperty docstrings are now writeable.
    https://hg.python.org/cpython/rev/5262dd507ee5

    @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
    easy interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants