Skip to content

@prop.setter decorators #45757

Closed
Closed

Description

@gvanrossum
BPO 1416
Nosy @gvanrossum, @tiran
Files
  • propset.diff
  • propset2.diff
  • propset3.diff
  • propset4.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/gvanrossum'
    closed_at = <Date 2007-11-10.22:13:02.864>
    created_at = <Date 2007-11-10.05:58:10.491>
    labels = []
    title = '@prop.setter decorators'
    updated_at = <Date 2007-11-10.22:13:02.863>
    user = 'https://github.com/gvanrossum'

    bugs.python.org fields:

    activity = <Date 2007-11-10.22:13:02.863>
    actor = 'gvanrossum'
    assignee = 'gvanrossum'
    closed = True
    closed_date = <Date 2007-11-10.22:13:02.864>
    closer = 'gvanrossum'
    components = []
    creation = <Date 2007-11-10.05:58:10.491>
    creator = 'gvanrossum'
    dependencies = []
    files = ['8724', '8726', '8728', '8729']
    hgrepos = []
    issue_num = 1416
    keywords = ['patch']
    message_count = 6.0
    messages = ['57345', '57354', '57356', '57358', '57359', '57361']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'christian.heimes', '_doublep']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1416'
    versions = ['Python 2.6', 'Python 3.0']

    Activity

    1. gvanrossum commented on Nov 10, 2007

      @gvanrossum
      MemberAuthor

      Here's an implementation of the idea I floated recently on python-dev
      (Subject: Declaring setters with getters). This implements the kind of
      syntax that I believe won over most folks in the end:

        @property
        def foo(self): ...
      
        @foo.setter
        def foo(self, value=None): ...

      There are also .getter and .deleter descriptors. This includes the hack
      that if you specify a setter but no deleter, the setter is called
      without a value argument when attempting to delete something. If the
      setter isn't ready for this, a TypeError will be raised, pretty much
      just as if no deleter was provided (just with a somewhat worse error
      message :-).

      I intend to check this into 2.6 and 3.0 unless there is a huge cry of
      dismay. Docs will be left to volunteers as always.

    2. self-assigned this
      on Nov 10, 2007
    3. doublep commented on Nov 10, 2007

      doublepmannequin
      Mannequin

      Looks great (regardless of how this is implemented). I always hated this
      def get_foo / def set_foo / foo = property (get_foo, set_foo).

    4. gvanrossum commented on Nov 10, 2007

      @gvanrossum
      MemberAuthor

      propset2.diff is a new version that improves upon the heuristic for
      making the deleter match the setter: when changing setters, if the old
      deleter is the same as the old setter, it will replace both the deleter
      and setter.

      This diff is relative to the 2.6 trunk; it applies to 3.0 too.

    5. gvanrossum commented on Nov 10, 2007

      @gvanrossum
      MemberAuthor

      propset3.diff removes the hack that makes the deleter equal to the
      setter when no separate deleter has been specified. If you want a
      single method to be used as setter and deleter, write this:

      @foo.setter
      @foo.deleter
      def foo(self, value=None): ...
    6. tiran commented on Nov 10, 2007

      @tiran
      Member

      Fixed a typo:

      +PyDoc_STRVAR(getter_doc,
      + "Descriptor to change the setter on a property.");
      ^^^

    7. gvanrossum commented on Nov 10, 2007

      @gvanrossum
      MemberAuthor

      Checked into trunk as revision 58929.

    8. 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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions