-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: adding backwards compatibility layer.
- Loading branch information
srossross
committed
Oct 8, 2012
1 parent
e14d46b
commit b987155
Showing
3 changed files
with
49 additions
and
1 deletion.
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,21 @@ | ||
''' | ||
Created on Oct 8, 2012 | ||
@author: sean | ||
''' | ||
from traity.tools.initializable_property import init_properties | ||
from traity.events import init_events | ||
|
||
|
||
class HasTraitsMeta(type): | ||
def __new__(cls, name, bases, dct): | ||
Klass = type.__new__(cls, name, bases, dct) | ||
init_properties(Klass) | ||
return Klass | ||
|
||
class HasTraits(object): | ||
__metaclass__ = HasTraitsMeta | ||
|
||
def __init__(self, **kwargs): | ||
self.__dict__.update(kwargs) | ||
init_events(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
''' | ||
Created on Oct 8, 2012 | ||
@author: sean | ||
''' | ||
from traity.traits import trait | ||
|
||
class Int(trait): | ||
def __init__(self, default=0): | ||
trait.__init__(self, type=int, fdefault=lambda self:default) | ||
|
||
# Special method to allow trait to be called with or without parens '()' | ||
# Method __init_property__ is invoked when init_properties is called | ||
|
||
@classmethod | ||
def __init_property__(cls, owner, key): | ||
int_trait = cls() | ||
setattr(owner, key, int_trait) | ||
trait.__init_property__(int_trait, owner, key) |