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

@prop.setter decorators #45757

Closed
gvanrossum opened this issue Nov 10, 2007 · 6 comments
Closed

@prop.setter decorators #45757

gvanrossum opened this issue Nov 10, 2007 · 6 comments
Assignees

Comments

@gvanrossum
Copy link
Member

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']

    @gvanrossum
    Copy link
    Member Author

    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.

    @gvanrossum gvanrossum self-assigned this Nov 10, 2007
    @doublep
    Copy link
    Mannequin

    doublep mannequin commented Nov 10, 2007

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

    @gvanrossum
    Copy link
    Member Author

    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.

    @gvanrossum
    Copy link
    Member Author

    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): ...

    @tiran
    Copy link
    Member

    tiran commented Nov 10, 2007

    Fixed a typo:

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

    @gvanrossum
    Copy link
    Member Author

    Checked into trunk as revision 58929.

    @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
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants