{ "info": { "author": "Michael Williamson", "author_email": "mike@zwobble.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4" ], "description": "Farthing: generate type annotations for Python source code by running it\n========================================================================\n\nFarthing will run arbitrary Python code while tracing the argument and return\ntypes of all functions within a given file or directory. Farthing can then\nautomatically add type annotations based on the types of the values it saw\nduring the execution run. This might be useful if you want to add static types\nto existing Python code, or for exploring codebases where you're not sure what\ntype a value has.\n\nFor instance, the following code:\n\n.. code-block:: python\n\n def factorial(n):\n result = 1\n \n for i in range(2, n + 1):\n result *= i\n \n return result\n\ncan be automatically transformed into:\n\n.. code-block:: python\n\n def factorial(n: int) -> int:\n result = 1\n \n for i in range(2, n + 1):\n result *= i\n \n return result\n\nby running Farthing against the following test file:\n\n.. code-block:: python\n\n from nose.tools import assert_equal\n\n import fact\n\n\n def test_fib():\n test_cases = [\n (0, 1),\n (1, 1),\n (2, 2),\n (3, 6),\n (4, 24),\n (5, 120),\n ]\n \n for index, value in test_cases:\n yield _check_fact, index, value\n\n\n def _check_fact(index, value):\n assert_equal(value, fact.factorial(index))\n \nUsage\n~~~~~\n\nFarthing can be called from the command line. The first argument should be the\nfile or directory that should have type annotations added to it. The other\narguments should be the Python script to run with any arguments. For instance:\n\n.. code-block:: sh\n\n farthing demo/fact.py _virtualenv/bin/nosetests demo/tests.py\n\n\nDemo\n~~~~\n\nTo run the demo, you can just run ``demo.sh``. To explain what it actually does:\n\n#. Run ``make bootstrap`` to set up the virtualenv with dependencies.\n\n#. Run ``. _virtualenv/bin/activate`` to enter the virtualenv.\n\n#. Run ``farthing demo/fact.py _virtualenv/bin/nosetests demo/tests.py`` to\n run ``_virtualenv/bin/nosetests demo/tests.py`` and add annotations to\n ``demo/fact.py`` based on the types of actual values used in the execution run.\n\nLimitations\n~~~~~~~~~~~\n\nAt the moment, Farthing is just a quick prototype, so currently has the\nfollowing limitations:\n\n* Annotations are added just using the name of the type, which may not be\n available in the current scope.\n\n* Type annotations cannot be added to the Python script being run.\n\n* The first type seen is used, rather than any attempt at finding a super-type.\n\nI'd be interested to see any projects along similar lines, so if you know of any,\nI'd be grateful if you let me know.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/mwilliamson/farthing", "keywords": "type", "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "farthing", "package_url": "https://pypi.org/project/farthing/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/farthing/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/mwilliamson/farthing" }, "release_url": "https://pypi.org/project/farthing/0.0.1/", "requires_dist": null, "requires_python": null, "summary": "Infer types by inspecting program runs", "version": "0.0.1" }, "last_serial": 1650108, "releases": { "0.0.1": [] }, "urls": [] }