| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e78178e commit b31339f
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,6 +24,31 @@ def my_abstract_method(self, ...): | |||
| 24 | 24 | return funcobj | |
| 25 | 25 | ||
| 26 | 26 | ||
| 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 | + | ||
| 27 | 52 | class _Abstract(object): | |
| 28 | 53 | ||
| 29 | 54 | """Helper class inserted into the bases by ABCMeta (using _fix_bases()). | |
| Back | FazBrowse Home | New Git URL |
0 commit comments