{ "info": { "author": "Gr\u00e9gory Salvan", "author_email": "apieum@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Other Environment", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "********\nDucktype\n********\n\n.. image:: https://pypip.in/v/ducktype/badge.png\n :target: https://pypi.python.org/pypi/ducktype\n\n\nProvides *isducktype*, a simple function to check ducktype.\n\n\nRoutine* 'A' is ducktype of 'B' when:\n - 'A' number of arguments is compatible with 'B' (names not checked)\n - OR A or B have varargs (*args) or keywords (**kwargs)\n\nArguments comparison between A and B is made within:\n - the number of required arguments to call A is between minimum and maximum number of B arguments\n - OR the number maximum of arguments to call A is between minimum and maximum number of B arguments\n\nrequired arguments means all arguments without defaults\n\nObject/Class 'A' is ducktype of 'B' when:\n - it has at least same public members names (public if they don't start by '_')\n - AND its methods are ducktypes of corresponding B methods.\n\nIf B has a method __ducktypecheck__, *isducktype* returns B.__ducktypecheck__(A)\n\n\nLike *isinstance* or *issubclass*, *isducktype* second argument can be either an objet or a tuple of objects.\n\n\nRoutine* in the sense: a user defined or builtins, function, method, or lambda.\n\n---------------------------------------------------------------------\n\n**Table of Contents**\n\n\n.. contents::\n :local:\n :depth: 1\n :backlinks: none\n\n\n=============\nInstallation\n=============\n\nInstall it from pypi::\n\n pip install ducktype\n\nor from sources::\n\n git clone git@github.com:apieum/ducktype.git\n cd ducktype\n python setup.py install\n\n=====\nUsage\n=====\n\n--------------------------------\nExample 1 - comparing functions:\n--------------------------------\n\n\n.. code-block:: python\n\n from ducktype import isducktype\n\n func_a = lambda a1, a2, a3=None: None\n func_b = lambda *b1: None\n func_c = lambda **c2: None\n func_d = lambda d1, d2: None\n func_e = lambda e1: None\n func_f = lambda f1, f2, f3, f4: None\n\n assert isducktype(func_b, func_a)\n assert isducktype(func_c, func_a)\n assert isducktype(func_d, func_a)\n assert isducktype(func_a, func_e) is False\n assert isducktype(func_e, func_a) is False\n assert isducktype(func_f, func_a) is False\n\n # with a tuple (== Or)\n assert isducktype(func_e, (func_a, func_b))\n assert isducktype(func_e, (func_a, func_d)) is False\n\n--------------------------------\nExample 2 - comparing objects:\n--------------------------------\n\n\n.. code-block:: python\n\n\n from ducktype import isducktype\n\n class A(object):\n _protected = 'hidden'\n __private = 'hidden'\n attr1 = None\n\n def method1(self, arg, kwargs=True):\n return kwargs\n\n def method2(self, arg):\n return arg\n\n class B(object):\n attr1 = None\n\n def method1(self, **kwargs):\n return kwargs\n\n def method2(self, arg1, arg2=None):\n return None\n\n class C(object):\n attr1 = False\n\n def method1(self, arg, kwarg):\n return arg\n\n class D(object):\n attr1 = False\n method1 = None\n method2 = None\n\n class E(object):\n def method1(self, **kwargs):\n return kwargs\n\n def method2(self, arg1, arg2=None):\n return None\n\n # it doesn't care if it's an instance or a class\n assert isducktype(A, B)\n assert isducktype(A(), B)\n assert isducktype(A, B())\n assert isducktype(A(), B())\n\n # You can call each A method as if it was C\n assert isducktype(A, C)\n # Reverse is not True\n assert isducktype(C, A) is False\n\n # Whereas D as same members as A, two are not functions\n assert isducktype(A, D) is False\n assert isducktype(D, A) is False\n\n # E need attribute \"attr1\" to ducktype A\n assert isducktype(A, E)\n assert isducktype(E, A) is False\n\n--------------------------------\nExample 3 - overriding default:\n--------------------------------\n\n\n.. code-block:: python\n\n\n from ducktype import isducktype\n\n class A(object):\n attr1 = None\n\n class B(object):\n attr1 = None\n attr2 = None\n\n class C(B):\n @classmethod\n def __ducktypecheck__(cls, maybe_duck):\n return hasattr(maybe_duck, 'attr1')\n\n class D(B):\n def __ducktypecheck__(self, maybe_duck):\n return hasattr(maybe_duck, 'attr1')\n\n # A must not ducktype B\n assert isducktype(A, B) is False\n\n # Returns A.__ducktypecheck__(C)\n assert isducktype(A, C)\n assert isducktype(A, D) is False\n assert isducktype(A, D())\n\n\n===========\nDevelopment\n===========\n\nAny feedback or help is welcome.\nYou can contact me by mail: apieum [at] gmail [dot] com\n\n\nLaunch test::\n\n git clone git@github.com:apieum/ducktype.git\n cd ducktype\n nosetests --with-spec --spec-color ./\n\n\n\n\n.. image:: https://secure.travis-ci.org/apieum/ducktype.png?branch=master\n :target: https://travis-ci.org/apieum/ducktype", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://www.python.org/pypi/ducktype", "keywords": null, "license": "LGPL", "maintainer": null, "maintainer_email": null, "name": "ducktype", "package_url": "https://pypi.org/project/ducktype/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/ducktype/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://www.python.org/pypi/ducktype" }, "release_url": "https://pypi.org/project/ducktype/0.2/", "requires_dist": null, "requires_python": null, "summary": "Check ducktyping", "version": "0.2" }, "last_serial": 935267, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "0b0790d1b59834a08b1c35931f1287ee", "sha256": "8a99c119429ae4334daf678bcb126c467f305baea17e5d3312b09324e84bbad9" }, "downloads": -1, "filename": "ducktype-0.1-py2.7.egg", "has_sig": false, "md5_digest": "0b0790d1b59834a08b1c35931f1287ee", "packagetype": "bdist_egg", "python_version": "2.7", "requires_python": null, "size": 2304, "upload_time": "2013-12-03T05:47:45", "url": "https://files.pythonhosted.org/packages/63/c2/7c8f0946498b1df01d8b2e83f80a8c79e0235bcc6af987fc5e6ed916d12e/ducktype-0.1-py2.7.egg" }, { "comment_text": "", "digests": { "md5": "ffef71c3952c9243790d2e34c0b6bb3b", "sha256": "c3c7cca408f1613f39bd37d7c06c8190b678d3e41f2bd6f3ce7b249b99526645" }, "downloads": -1, "filename": "ducktype-0.1-py3.3.egg", "has_sig": false, "md5_digest": "ffef71c3952c9243790d2e34c0b6bb3b", "packagetype": "bdist_egg", "python_version": "3.3", "requires_python": null, "size": 2406, "upload_time": "2013-12-03T05:47:54", "url": "https://files.pythonhosted.org/packages/0b/c0/02af097fd4df5ccadb1323b2d0e11f1b0b2d68947f5bf4cf97d27c644500/ducktype-0.1-py3.3.egg" }, { "comment_text": "", "digests": { "md5": "36af3ee44f22a2cb086517439bc30ebf", "sha256": "526e2004bfb176eac891d7eb5b8832327646b1fb236b7249630e25c9418ae458" }, "downloads": -1, "filename": "ducktype-0.1.tar.gz", "has_sig": false, "md5_digest": "36af3ee44f22a2cb086517439bc30ebf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4530, "upload_time": "2013-12-03T05:47:41", "url": "https://files.pythonhosted.org/packages/4d/53/38c9320da45a9c0c64ff7743131fb0d11b20c803afd65a62263c06869b4b/ducktype-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "40fd7ea73d7175aeced0f6e1c6944b22", "sha256": "62e0c0c6748705bfd9169b42042817d0838f2a91256e76ebfc493a9d3511e095" }, "downloads": -1, "filename": "ducktype-0.2-py2.7.egg", "has_sig": false, "md5_digest": "40fd7ea73d7175aeced0f6e1c6944b22", "packagetype": "bdist_egg", "python_version": "2.7", "requires_python": null, "size": 10998, "upload_time": "2013-12-04T01:16:39", "url": "https://files.pythonhosted.org/packages/95/b7/774777e4866cbc8cb83927f7d946fa0ee9d4bc60487760f9acd0e7307115/ducktype-0.2-py2.7.egg" }, { "comment_text": "", "digests": { "md5": "4bf652ca81e7869ada643822452191c3", "sha256": "58cbb59e7ec66631ac01e46d94749b86a355373541e004ffdb600107435c871d" }, "downloads": -1, "filename": "ducktype-0.2-py3.3.egg", "has_sig": false, "md5_digest": "4bf652ca81e7869ada643822452191c3", "packagetype": "bdist_egg", "python_version": "3.3", "requires_python": null, "size": 11598, "upload_time": "2013-12-04T01:16:49", "url": "https://files.pythonhosted.org/packages/8d/a5/9ba8998dcca628eff221777b8bf03dc7bb21e31d737985107d2d99348ccb/ducktype-0.2-py3.3.egg" }, { "comment_text": "", "digests": { "md5": "7586b525ebfe6692221af2006e2d0462", "sha256": "d33f3401391acda266afd39b36a768638972a61ad10c0fe54473bf0c9859b2d8" }, "downloads": -1, "filename": "ducktype-0.2.tar.gz", "has_sig": false, "md5_digest": "7586b525ebfe6692221af2006e2d0462", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7590, "upload_time": "2013-12-04T01:16:37", "url": "https://files.pythonhosted.org/packages/89/6f/7fcde267e1f3e94c5e8575698f39513ec76486656337d01e83870988830e/ducktype-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "40fd7ea73d7175aeced0f6e1c6944b22", "sha256": "62e0c0c6748705bfd9169b42042817d0838f2a91256e76ebfc493a9d3511e095" }, "downloads": -1, "filename": "ducktype-0.2-py2.7.egg", "has_sig": false, "md5_digest": "40fd7ea73d7175aeced0f6e1c6944b22", "packagetype": "bdist_egg", "python_version": "2.7", "requires_python": null, "size": 10998, "upload_time": "2013-12-04T01:16:39", "url": "https://files.pythonhosted.org/packages/95/b7/774777e4866cbc8cb83927f7d946fa0ee9d4bc60487760f9acd0e7307115/ducktype-0.2-py2.7.egg" }, { "comment_text": "", "digests": { "md5": "4bf652ca81e7869ada643822452191c3", "sha256": "58cbb59e7ec66631ac01e46d94749b86a355373541e004ffdb600107435c871d" }, "downloads": -1, "filename": "ducktype-0.2-py3.3.egg", "has_sig": false, "md5_digest": "4bf652ca81e7869ada643822452191c3", "packagetype": "bdist_egg", "python_version": "3.3", "requires_python": null, "size": 11598, "upload_time": "2013-12-04T01:16:49", "url": "https://files.pythonhosted.org/packages/8d/a5/9ba8998dcca628eff221777b8bf03dc7bb21e31d737985107d2d99348ccb/ducktype-0.2-py3.3.egg" }, { "comment_text": "", "digests": { "md5": "7586b525ebfe6692221af2006e2d0462", "sha256": "d33f3401391acda266afd39b36a768638972a61ad10c0fe54473bf0c9859b2d8" }, "downloads": -1, "filename": "ducktype-0.2.tar.gz", "has_sig": false, "md5_digest": "7586b525ebfe6692221af2006e2d0462", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7590, "upload_time": "2013-12-04T01:16:37", "url": "https://files.pythonhosted.org/packages/89/6f/7fcde267e1f3e94c5e8575698f39513ec76486656337d01e83870988830e/ducktype-0.2.tar.gz" } ] }