Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b31339f

Browse files
committed
Add @abstractproperty.
1 parent e78178e commit b31339f

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

Lib/abc.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,31 @@ def my_abstract_method(self, ...):
2424
return funcobj
2525

2626

27+
class abstractproperty(property):
28+
"""A decorator indicating abstract properties.
29+
30+
Requires that the metaclass is ABCMeta or derived from it. A
31+
class that has a metaclass derived from ABCMeta cannot be
32+
instantiated unless all of its abstract properties are overridden.
33+
34+
Usage:
35+
36+
class C(metaclass=ABCMeta):
37+
@abstractproperty
38+
def my_abstract_property(self):
39+
...
40+
41+
This defines a read-only property; you can also define a read-write
42+
abstract property using the 'long' form of property declaration:
43+
44+
class C(metaclass=ABCMeta):
45+
def getx(self): ...
46+
def setx(self, value): ...
47+
x = abstractproperty(getx, setx)
48+
"""
49+
__isabstractmethod__ = True
50+
51+
2752
class _Abstract(object):
2853

2954
"""Helper class inserted into the bases by ABCMeta (using _fix_bases()).

0 commit comments

Comments
 (0)