This repository has been archived by the owner on Mar 27, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started cleaning up the way of dealing with __magic__ methods
- Loading branch information
Tim Cuthbertson
committed
Apr 24, 2009
1 parent
5c9639d
commit 652e7bb
Showing
6 changed files
with
71 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
def ensure_singleton_class(self): | ||
try: | ||
object.__getattr__(self, '_singleton_class_original_bases') | ||
except AttributeError: | ||
self._singleton_class_original_bases = type(self).__bases__ | ||
# make a new class that inherits from my current class, with the same name | ||
new_class = type(type(self).__name__, (type(self),), {}) | ||
object.__setattr__(self, '__class__', new_class) | ||
|
||
def revert_singleton_class(self): | ||
try: | ||
object.__getattr__(self, '_singleton_class_original_bases') | ||
except: | ||
return | ||
type(self).__bases__ = self._singleton_class_original_bases | ||
|
||
|
||
#handy mixin class | ||
class SingletonClass(object): | ||
def _ensure_singleton_class(self): | ||
ensure_singleton_class(self) | ||
|
||
def _revert_singleton_class(self): | ||
revert_singleton_class(self) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters