Home

Welcome

ducktypes is a duck typing support library.

It is designed to let the user work with objects depending on their current runtime behaviour, not their class or their register-based (e.g. ABC, zope.interface) interface.

Whet your appetite

from ducktypes.ducktype import Duck

class MyObject(object):
    def some_method(self, a, b):
        pass
    def another_method(self, x):
        pass


class AnotherObject(object):
    def some_method(self, a, b):
        pass
    def another_method(self, a):
        pass

class AnotherDifferentObject(object):
    def some_method(self, a, b, c):
        pass
    def another_method(self, a):
        pass

duck = Duck(MyObject())

print "AnotherObject instances implement MyObject interface: ", duck.maybe_implemented_by(AnotherObject())
print "AnotherDifferentObject instances implement MyObject interface:", duck.maybe_implemented_by(AnotherDifferentObject())


OUTPUT:

AnotherObject instances implement MyObject interface:  True
AnotherDifferentObject instances implement MyObject interface: False

More

ducktypes supports checking for special methods, classmethods, static methods, function attributes; the only thing that matters to it is the way an object *behaves* at runtime.

If you're tired of doing getattr(obj, "some_method", False) calls in your code, that's what you need.

See the README for more info and to learn about its caveats.

Discussion

Discussion is hosted at the pydenji-users mailing list / google group:

http://groups.google.com/group/pydenji-users

Issues

Tickets can be opened through the bitbucket bugtracker

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.