Skip to content

Commit

Permalink
Merge pull request #266 from SpiNNakerManchester/abstractproperty
Browse files Browse the repository at this point in the history
remove abstractproperty
  • Loading branch information
rowleya committed Jan 16, 2024
2 parents 0302811 + a524410 commit 296d06b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 58 deletions.
53 changes: 0 additions & 53 deletions spinn_utilities/abstract_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,59 +40,6 @@ def my_abstract_method(self, ...):
return funcobj


# pylint: disable=invalid-name
class abstractproperty(property):
"""
A decorator indicating abstract properties.
Requires that the metaclass is :py:class:`AbstractBase` or derived from
it. A class that has a metaclass derived from :py:class:`AbstractBase`
cannot be instantiated unless all of its abstract properties are
overridden. The abstract properties can be called using any of the normal
'super' call mechanisms.
Usage::
class C(object, metaclass=AbstractBase):
@abstractproperty
def my_abstract_property(self):
...
This defines a read-only property; you can also define a read-write
abstract property using the 'long' form of property declaration::
class C(object, metaclass=AbstractBase):
def getx(self): ...
def setx(self, value): ...
x = abstractproperty(getx, setx)
.. note::
When documenting abstract properties, remember to document them as if
they are nouns, not verbs; they are things about the object that may
be observed as many times as the user of the class desires.
.. warning::
This does *not* work with mypy type checking! When doing typed abstract
properties, you should instead do::
@property
@abstractmethod
def my_abstract_property(self) -> int:
...
I assume that this is because ``@property`` is a special form in mypy.
.. warning::
Implementations should be idempotent; fetching the property twice in a
row should get an equivalent value with no (meaningful) change to the
state of the object (assuming no other non-property methods of the
object are invoked between).
This is an assumption that debuggers make. *Do not violate it!*
"""
__isabstractmethod__ = True


class AbstractBase(type):
"""
Metaclass for defining Abstract Base Classes (AbstractBases).
Expand Down
5 changes: 3 additions & 2 deletions unittests/abstract_base/abstract_has_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from spinn_utilities.abstract_base import AbstractBase, abstractproperty
from spinn_utilities.abstract_base import AbstractBase, abstractmethod


class AbstractHasId(object, metaclass=AbstractBase):
Expand All @@ -24,7 +24,8 @@ class AbstractHasId(object, metaclass=AbstractBase):
def has_id(self):
return True

@abstractproperty
@property
@abstractmethod
def id(self):
""" The id of the item
Expand Down
6 changes: 3 additions & 3 deletions unittests/abstract_base/abstract_has_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from spinn_utilities.abstract_base import (
AbstractBase, abstractproperty, abstractmethod)
from spinn_utilities.abstract_base import (AbstractBase, abstractmethod)


class AbstractHasLabel(object, metaclass=AbstractBase):
Expand All @@ -22,7 +21,8 @@ class AbstractHasLabel(object, metaclass=AbstractBase):

__slots__ = ()

@abstractproperty
@property
@abstractmethod
def label(self):
""" The label of the item
Expand Down

0 comments on commit 296d06b

Please sign in to comment.