Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(169267)

Side by Side Diff: Lib/abc.py

Issue 11610: Improving property to accept abstract methods
Patch Set: Created 8 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2007 Google, Inc. All Rights Reserved. 1 # Copyright 2007 Google, Inc. All Rights Reserved.
2 # Licensed to PSF under a Contributor Agreement. 2 # Licensed to PSF under a Contributor Agreement.
3 3
4 """Abstract Base Classes (ABCs) according to PEP 3119.""" 4 """Abstract Base Classes (ABCs) according to PEP 3119."""
5 5
6 from _weakrefset import WeakSet 6 from _weakrefset import WeakSet
7 7
8 def abstractmethod(funcobj): 8 def abstractmethod(funcobj):
9 """A decorator indicating abstract methods. 9 """A decorator indicating abstract methods.
10 10
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 ... 82 ...
83 83
84 This defines a read-only property; you can also define a read-write 84 This defines a read-only property; you can also define a read-write
85 abstract property using the 'long' form of property declaration: 85 abstract property using the 'long' form of property declaration:
86 86
87 class C(metaclass=ABCMeta): 87 class C(metaclass=ABCMeta):
88 def getx(self): ... 88 def getx(self): ...
89 def setx(self, value): ... 89 def setx(self, value): ...
90 x = abstractproperty(getx, setx) 90 x = abstractproperty(getx, setx)
91 """ 91 """
92 warnings.warn(
durban 2011/03/19 21:36:09 warnings is not imported. Also if you put the war
dsdale24 2011/03/19 22:13:42 Good point.
93 "abstractproperty will be removed in future versions. "
94 "Use 'property' in conjunction with 'abstractmethod' instead.",
95 DeprecationWarning, stacklevel=2
96 )
92 __isabstractmethod__ = True 97 __isabstractmethod__ = True
93 98
94 99
95 class ABCMeta(type): 100 class ABCMeta(type):
96 101
97 """Metaclass for defining Abstract Base Classes (ABCs). 102 """Metaclass for defining Abstract Base Classes (ABCs).
98 103
99 Use this metaclass to create an ABC. An ABC can be subclassed 104 Use this metaclass to create an ABC. An ABC can be subclassed
100 directly, and then acts as a mix-in class. You can also register 105 directly, and then acts as a mix-in class. You can also register
101 unrelated concrete classes (even built-in classes) and unrelated 106 unrelated concrete classes (even built-in classes) and unrelated
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 cls._abc_cache.add(subclass) 211 cls._abc_cache.add(subclass)
207 return True 212 return True
208 # Check if it's a subclass of a subclass (recursive) 213 # Check if it's a subclass of a subclass (recursive)
209 for scls in cls.__subclasses__(): 214 for scls in cls.__subclasses__():
210 if issubclass(subclass, scls): 215 if issubclass(subclass, scls):
211 cls._abc_cache.add(subclass) 216 cls._abc_cache.add(subclass)
212 return True 217 return True
213 # No dice; update negative cache 218 # No dice; update negative cache
214 cls._abc_negative_cache.add(subclass) 219 cls._abc_negative_cache.add(subclass)
215 return False 220 return False
OLDNEW

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+