Skip to content

Commit

Permalink
ENH: adding backwards compatibility layer.
Browse files Browse the repository at this point in the history
  • Loading branch information
srossross committed Oct 8, 2012
1 parent e14d46b commit b987155
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,13 @@

setup(name='traity',
version='0.0.1',
packages=find_packages())
description='Extended Python Porperties',
packages=find_packages(),
author='Sean Ross-Ross',
author_email='srossross@enthought.com',
url='http://srossross.github.com/traity',
classifiers=['Programming Language :: Python :: 2',
'Programming Language :: Python :: 3'],
license='BSD',
)

21 changes: 21 additions & 0 deletions traity/compat/has_traits.py
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)
19 changes: 19 additions & 0 deletions traity/compat/trait_types.py
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)

0 comments on commit b987155

Please sign in to comment.