Skip to content
/ spy Public

Clone user-defined classes in Python, make rapid-prototyping a breeze.

License

Notifications You must be signed in to change notification settings

ziord/spy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spy image

built with python Spy License python versions (3.6+) issues stars forks


spy

spy is a package that enables automated cloning of user-defined Python classes.

Example

from spy.cc import clone

class SimpleOriginal:
    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return f"{self.__class__.__name__}({self.name})"

    def foo(self):
        return self.name + 'foo'
    
    def bar(self):
        return self.name + 'bar'


@clone(SimpleOriginal)
class SimpleClone:
    pass


# tests
sc_obj = SimpleClone('test')
print(sc_obj.foo())  # testfoo
print(sc_obj.bar())  # testbar
print(sc_obj)  # SimpleClone(test)
print(type(sc_obj))  # <class '__main__.SimpleClone'>
print(sc_obj.foo, sc_obj.bar)  
# <bound method SimpleClone.foo of SimpleClone(test)> <bound method SimpleClone.bar of SimpleClone(test)>

Tests

Tested for Python 3.7, compatible with Python 3.6+. See the tests folder.

Installation

Clone this repo, and do:

cd spy
python setup.py install

Caution

spy does not work for built-in types.
A BuiltinTypeNotSupportedException is raised if you try to clone builtin types.
See tests for more information.

License

MIT

About

Clone user-defined classes in Python, make rapid-prototyping a breeze.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages