Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108865

How do I subclass the @property setter method?

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Christopher Reimer <christopher_reimer@icloud.com>
Newsgroups comp.lang.python
Subject How do I subclass the @property setter method?
Date Fri, 20 May 2016 11:50:37 -0700
Lines 49
Message-ID <mailman.55.1463773847.27390.python-list@python.org> (permalink)
References <2200dfd0-7470-0c86-c015-a6a14a2f51f2@icloud.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de rvrBsTobHDe1ECDChjroRAzFeYjCLZEemnqF/V8MV0Cg==
Return-Path <christopher_reimer@icloud.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'test,': 0.05; 'subject:How': 0.09; '@property': 0.09; 'ide': 0.09; 'subclass': 0.09; 'subject:method': 0.09; 'bug': 0.10; 'def': 0.13; 'value.': 0.15; 'complains': 0.16; 'declaration': 0.16; 'happy.': 0.16; 'hint': 0.16; 'placeholder': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'redundant.': 0.16; 'subclassing': 0.16; 'changes': 0.20; 'work,': 0.21; 'correctly.': 0.22; 'decorator': 0.22; 'pass': 0.22; 'seems': 0.23; 'represents': 0.23; "haven't": 0.24; 'feature': 0.24; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'chris': 0.26; 'received:17': 0.27; "i'm": 0.30; 'board': 0.30; 'code': 0.30; 'class.': 0.30; 'received:10.0.0': 0.32; 'changed': 0.33; 'class': 0.33; 'received:10.0': 0.34; 'false': 0.35; 'unit': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:?': 0.36; 'received:10': 0.37; 'signature': 0.37; 'thank': 0.38; 'test': 0.39; 'sure': 0.39; 'does': 0.39; 'subject:the': 0.39; 'to:addr:python.org': 0.40; 'space': 0.40; 'header:MIME-version:1': 0.60; 'greetings,': 0.61; 'engine': 0.62; 'skip:n 10': 0.62; 'dict.': 0.84; 'playable': 0.84; 'signature.': 0.84
X-Proofpoint-Virus-Version vendor=fsecure engine=2.50.10432:,, definitions=2016-05-20_05:,, signatures=0
X-Proofpoint-Spam-Details rule=notspam policy=default score=0 spamscore=0 clxscore=1015 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1510270003 definitions=main-1605200232
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=icloud.com; s=4d515a; t=1463770237; bh=2wDPFGLyl7IKgBmZEWcr9YjiPlE0KvDrqIdocVX9ACk=; h=To:From:Subject:Message-id:Date:MIME-version:Content-type; b=Lam6ZKJ+mKZUfn3apH/f+4bsuL3i7X5Xv2IGvES+kE/Xg33+yuD+319SCQZH6r+kv nOcHETGtsA+sVQu+zFgF1U4Hfm9CMT0zVi4C8IpZQZDvsQBbU/x4oz4p6byC6hQGzC TioXplQ08a3am2F+nmeU58ctrTlmDYAxJe+4Z6ZJstYlUq0Oc9CB9tCxtu1lv1M3U8 NgpERMbQDb2hGnwIp3ivqUdSnzqGcbYlSV/+S/RnT6AxdRNu1awiHOQp31hcCdrQzd pd0g37se1xg+cPsjazOsj0ARtOup74QF/gJkCYqhr3kVMu/xFyqiueiJTky2VH30F7 gnkJNyi2HgBnA==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.22
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <2200dfd0-7470-0c86-c015-a6a14a2f51f2@icloud.com>
Xref csiph.com comp.lang.python:108865

Show key headers only | View raw


Greetings,

My chess engine has a Piece class with the following methods that use 
the @property decorator to read and write the position value.

     @property
     def position(self):
         return self._position

     @position.setter
     def position(self, position):
         if self._first_move:
             self._first_move = False
         self._position = position

Blank is a subclass of the Piece class that represents an empty space on 
the board and  is a placeholder in the Board class _state dict. Since 
Blank is a placeholder and not a playable game piece, I want to make 
@position.setter non-operational (i.e, make no changes to the position 
value).

     @Piece.position.setter
     def position(self, position):
         pass

This code works and the corresponding unit test blows up because I 
haven't changed it yet, but the PyCharm IDE complains that the 
Blank.position signature doesn't match the Piece.position signature. 
Never mind that I copy and paste the identical declaration from the 
Piece class.

This code does work, blows up the unit test, and keeps PyCharm happy.

     @property
     def position(self):
         return super().position

     @position.setter
     def position(self, position):
         pass

Re-declaring @property and calling super seems redundant.  Not sure if I 
found a bug with the PyCharm hint feature or I'm not subclassing the 
@property setter correctly. Which is it?

Thank you,

Chris R.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

How do I subclass the @property setter method? Christopher Reimer <christopher_reimer@icloud.com> - 2016-05-20 11:50 -0700

csiph-web